Boost logo

Boost :

Subject: Re: [boost] [Serialization] this seems wrong
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-12-02 13:26:07


Kenny Riddile wrote:
> David Abrahams wrote:
>> on Wed Nov 26 2008, Kenny Riddile <kfriddile-AT-yahoo.com> wrote:
>>
>>> #define BOOST_CLASS_EXPORT_GUID(T, K) \
>>> namespace \
>>> { \
>>> ::boost::archive::detail::guid_initializer< T > const & \
>>> BOOST_PP_CAT(boost_serialization_guid_initializer_, __LINE__)
>>> \
>>> = ::boost::serialization::singleton< \
>>> ::boost::archive::detail::guid_initializer< T > \
>>> >::get_mutable_instance().export_guid(K); \
>>> }
>>>
>>> with:
>>>
>>> #define BOOST_CLASS_EXPORT_GUID(T, K) \
>>> namespace \
>>> { \
>>> ::boost::archive::detail::guid_initializer< T > const & \
>>> BOOST_PP_CAT(boost_serialization_guid_initializer_, T)
>>> \
>>
>> That will only work if T is a simple identifier or number. A name like
>> std::pair<int,int> would fail.
>>
>> I don't remember offhand whether class template specializations get
>> exported by Boost.Serialization, but it seems to me that this doesn't
>> need to be so hard in any case. You can probably make the
>> namespace-scope variable a static member of a class template and use an
>> explicit instantiation to generate it. If it works, there's no need for
>> an unnamed namespace and no name clashes.
>>

I don't know about getting rid of the unnamed namespace but essentially
we just need a unique name per type in a translation unit.. so how about:

#define BOOST_CLASS_EXPORT_GUID(T, K) \
namespace \
{ \
     template< typename U > \
     class init_guid \
     { \
         static ::boost::archive::detail::guid_initializer<U> const & \
         guid_initializer_; \
     }; \
     template<> ::boost::archive::detail::guid_initializer<T> const & \
         init_guid<T>::guid_initializer_ = \
             ::boost::serialization::singleton< \
                 ::boost::archive::detail::guid_initializer<T> \
>::get_mutable_instance().export_guid(K); \
}

-- 
Michael Marcin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk