Ticket #1711: header_ordering_fix.2.patch

File header_ordering_fix.2.patch, 5.0 KB (added by Sohail Somani <boost-trac@…>, 15 years ago)

Doesn't use ADL. Don't know what I was thinking. Uses enable_if to instantiate the right stuff.

  • boost/serialization/export.hpp

     
    112112    );
    113113}
    114114
     115// This trait is used to force the compiler to do a dependent name
     116// lookup on instantiate_ptr_serialization. When classes are exported,
     117// they specialize this trait to inherit from mpl::true_. This in
     118// turn causes a different set of overloads to be selected. The key
     119// thing is that the name lookup is delayed to instantiation time.
     120template<typename T>
     121struct force_dependent_name_lookup
     122  : boost::mpl::false_ {};
     123
    115124template<class T>
    116125struct guid_initializer
    117126
     
    119128        // generates the statically-initialized objects whose constructors
    120129        // register the information allowing serialization of T objects
    121130        // through pointers to their base classes.
    122         instantiate_ptr_serialization((T*)0, 0);
     131        instantiate_ptr_serialization((T*)0,0,
     132                                      typename force_dependent_name_lookup<T>::type());
    123133        return *this;
    124134    }
    125135    const guid_initializer & export_guid(char const* key, mpl::true_){
     
    144154} // namespace archive
    145155} // namespace boost
    146156
     157// Internal macro: This macro specializes
     158// force_dependent_name_loookup. See explanation above.
     159#define BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T)                    \
     160namespace boost { namespace archive { namespace detail {                \
     161template<> struct force_dependent_name_lookup<T> : public mpl::true_{}; \
     162}}}
     163
    147164#define BOOST_CLASS_EXPORT_GUID(T, K)                                               \
     165BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T)                                        \
    148166namespace                                                                           \
    149167{                                                                                   \
    150168    ::boost::archive::detail::guid_initializer< T > const &                         \
  • boost/archive/detail/register_archive.hpp

     
    44#ifndef BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP
    55# define BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP
    66
     7#include <boost/utility/enable_if.hpp>
     8
    79namespace boost { namespace archive { namespace detail {
    810
    911template <class Archive, class Serializable>
     
    1719struct _ptr_serialization_support
    1820  : ptr_serialization_support<Archive,Serializable>
    1921{
    20     typedef int type;
     22    typedef void type;
    2123};
    2224
    23 // This function gets called, but its only purpose is to participate
    24 // in overload resolution with the functions declared by
    25 // BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
    26 template <class Serializable>
    27 void instantiate_ptr_serialization(Serializable*, int) {}
    28 
    29 // The function declaration generated by this macro never actually
    30 // gets called, but its return type gets instantiated, and that's
    31 // enough to cause registration of serialization functions between
    32 // Archive and any exported Serializable type.  See also:
    33 // boost/serialization/export.hpp
     25// enable_if causes _ptr_serialization_support to be instantiated for all
     26// archives that get registered. This function is actually called.
     27// See also: boost/serialization/export.hpp
    3428# define BOOST_SERIALIZATION_REGISTER_ARCHIVE(Archive)                  \
    3529namespace boost { namespace archive { namespace detail {                \
    3630                                                                        \
    3731template <class Serializable>                                           \
    38 typename _ptr_serialization_support<Archive, Serializable>::type        \
    39 instantiate_ptr_serialization( Serializable*, Archive* );               \
     32typename boost::enable_if<Archive::is_loading,                          \
     33                          typename                                      \
     34                          _ptr_serialization_support<Archive,           \
     35                                                     Serializable>::type >::type \
     36instantiate_ptr_serialization( Serializable*,                           \
     37                               Archive*,                                \
     38                               boost::mpl::true_){}                     \
    4039                                                                        \
    4140}}}
    4241
  • libs/serialization/test/test_exported.cpp

     
    1818}
    1919#endif
    2020
     21#include <boost/serialization/export.hpp>
    2122#include <boost/serialization/base_object.hpp>
    2223#include <boost/serialization/type_info_implementation.hpp>
    2324#include <boost/archive/archive_exception.hpp>
    2425#include "test_tools.hpp"
    25 #include <boost/serialization/export.hpp>
    2626
    2727#include "base.hpp"
    2828