
I would hope that soon we might think of releasing an updated version of boost - 1.33 As far as I know this might include a)bug fixes for herefore untested combinations of compilers, varients, etc b)Jonathon Turkanis stream bufffer library c)Other libraries (Ranges?) d)Serialization library - bugfixes and DLL version Robert Ramey

If I had to vote somewhere in Boost, I would approved the suggestion of Robert since the serialization in DLL is a long awaited feature!! Francis ANDRE -- A good friend will come bail you out of jail.......... but, a true friend....will be sitting next to you saying: "...that was fun." "Robert Ramey" <ramey@rrsd.com> a écrit dans le message de news:csa9rn$le4$1@sea.gmane.org...
I would hope that soon we might think of releasing an updated version of boost - 1.33
As far as I know this might include
a)bug fixes for herefore untested combinations of compilers, varients, etc b)Jonathon Turkanis stream bufffer library c)Other libraries (Ranges?) d)Serialization library - bugfixes and DLL version
Robert Ramey
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Actually, my suggestion isn't motivated by inclusion of any feature in particular. Its more of a desire to avoid the painful experience of last time. I think more frequent releases in smaller increments would have the following benefits. a) I think it would be easier b) authors would be encouraged to keep code maintained as opposed to "doing it before the next release" c) code would be better as many seeming small changes are discovered when the library gets out into the real world. d) libary authors wouldn't feel pressured to include development code prematurely in order to "make the release" . Currently, if an opportunity to include somethng is missed, its a long time before it appears again. I realize this is predicated on a re-organization of the testing methodology. I have made suggestions along this line in another recent email. Robert Ramey Francis ANDRE wrote:
If I had to vote somewhere in Boost, I would approved the suggestion of Robert since the serialization in DLL is a long awaited feature!!
FYI - I had anticipated that packaging the serialization library as a DLL with auto-link would be a piece of cake. It turned out to be a huge hassle for a number of non-obvious reasons. This is sort of the story of my life. Robert Ramey

Robert Ramey wrote:
I would hope that soon we might think of releasing an updated version of boost - 1.33
As far as I know this might include
a)bug fixes for herefore untested combinations of compilers, varients, etc b)Jonathon Turkanis stream bufffer library c)Other libraries (Ranges?) d)Serialization library - bugfixes and DLL version
Richard Peters posted some diffs in late November for serialization of variants. My "patch" didn't like the diffs and gcc didn't like some of the code, but it's all cleaned up now, works. I wrote a little test module which might need to be more thorough (if so, let me know what else it needs to do...) I don't see reactions to the code in the archives from serialization or variant authors, though. The library files are at: http://svn.resophonic.com/pub/boost/boost/variant.hpp http://svn.resophonic.com/pub/boost/boost/variant/detail/visitation_impl.hpp and tests, http://svn.resophonic.com/pub/boost/libs/serialization/test/test_variant.cpp - troy d. straszheim

I have had requests for this from time to time. Indeed, I have interest myself. However, authors of boost::variant havn't shown an interest in doing this. So I would suggest: a) Make sure it has a test. Ideally it should be in the same form as the other serialization tests so it can be just "dropped in" to the current test setup. b) Make a simple html page to describe any "gotchas" (if any) or other quirks one has to be aware of. c) Prepare to receive lots of advice on how you "should" have done it. Robert Ramey but no interest in troy d. straszheim wrote:
Robert Ramey wrote:
I would hope that soon we might think of releasing an updated version of boost - 1.33
As far as I know this might include
a)bug fixes for herefore untested combinations of compilers, varients, etc b)Jonathon Turkanis stream bufffer library c)Other libraries (Ranges?) d)Serialization library - bugfixes and DLL version
Richard Peters posted some diffs in late November for serialization of variants. My "patch" didn't like the diffs and gcc didn't like some of the code, but it's all cleaned up now, works. I wrote a little test module which might need to be more thorough (if so, let me know what else it needs to do...) I don't see reactions to the code in the archives from serialization or variant authors, though. The library files are at:
http://svn.resophonic.com/pub/boost/boost/variant/detail/visitation_impl.hpp
and tests,
http://svn.resophonic.com/pub/boost/libs/serialization/test/test_variant.cpp
- troy d. straszheim
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Robert Ramey wrote:
I have had requests for this from time to time. Indeed, I have interest myself. However, authors of boost::variant havn't shown an interest in doing this. So I would suggest:
I think I've got these covered:
a) Make sure it has a test. Ideally it should be in the same form as the other serialization tests so it can be just "dropped in" to the current test setup.
Naturally. I started with one of the serialization tests, it gets run 5 times on the 5 different types of archive like the others.
b) Make a simple html page to describe any "gotchas" (if any) or other quirks one has to be aware of.
Far as I can see, there really aren't any gotchas, it just serializes variants.
c) Prepare to receive lots of advice on how you "should" have done it.
Sure, I'd be glad to modify it to please the hordes, but I take neither credit nor blame, yet, it is from message news://news.gmane.org:119/co291u$68j1@sea.gmane.org Thread title "Serializing a variant", in which Richard Peters says:
The code in the previous posting gives a general solution for serializing a variant, so that there is no need to make an ad-hoc serializer for every different variant.
-t

Hi Troy (and others interested in this issue), When I have some available time, I will take a look at the code for serialization. Sorry for not replying sooner, but I don't check up on the Boost list as often as I should. One question, as I'm not familiar with the serialization library. What effect do the proposed changes have on those users of variant who do not need/want serialization support? Obviously there is the addition #include, but does this imply overhead, or is the header simply forward declares in the spirit of <iosfwd>? Thanks, Eric troy d. straszheim wrote:
Robert Ramey wrote:
I have had requests for this from time to time. Indeed, I have interest myself. However, authors of boost::variant havn't shown an interest in doing this. So I would suggest:
I think I've got these covered:
a) Make sure it has a test. Ideally it should be in the same form as the other serialization tests so it can be just "dropped in" to the current test setup.
Naturally. I started with one of the serialization tests, it gets run 5 times on the 5 different types of archive like the others.
b) Make a simple html page to describe any "gotchas" (if any) or other quirks one has to be aware of.
Far as I can see, there really aren't any gotchas, it just serializes variants.
c) Prepare to receive lots of advice on how you "should" have done it.
Sure, I'd be glad to modify it to please the hordes, but I take neither credit nor blame, yet, it is from message news://news.gmane.org:119/co291u$68j1@sea.gmane.org Thread title "Serializing a variant", in which Richard Peters says:
The code in the previous posting gives a general solution for serializing a variant, so that there is no need to make an ad-hoc serializer for every different variant.
-t
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

One question, as I'm not familiar with the serialization library. What effect do the proposed changes have on those users of variant who do not need/want serialization support? Obviously there is the addition #include, but does this imply overhead, or is the header simply forward declares in the spirit of <iosfwd>?
Implement everything in separate header (f.e. boost/variant/serialization.hpp) and there wouldn't be any cost for people who don't need that Gennadiy

Gennadiy Rozental wrote:
One question, as I'm not familiar with the serialization library. What effect do the proposed changes have on those users of variant who do not need/want serialization support? Obviously there is the addition #include, but does this imply overhead, or is the header simply forward declares in the spirit of <iosfwd>?
Implement everything in separate header (f.e. boost/variant/serialization.hpp) and there wouldn't be any cost for people who don't need that
Gennadiy
As it stands the implementaion is intrusive, separate header won't work. The author added a couple of internal vistior types. But I will have a look and see exactly what the story is, I didn't think of this when I cleaned it up. I also notice that what I put up has debugging cruft in it that I overlooked, sorry if anybody played with it and it didn't work... troy d. straszheim

Serialization for all STL collections is done without changing STL. So, if one is not using serialization it doesn't have to be included. I was able to implement serialization for boost::smart_ptr without changing it. However, my implemention is dependent on the smart pointer implementation and required access to a couple of private variables from the smart pointer implementation. The smart pointer didn't expose enough functionality to do it any other way without makeing changes to the serialization library itself. This raised hackle in some quarters. The concern was since smart_ptr is to conform to a standard, it should be serializable while relying only on its public standard interface. However, doing this means hanging on an kludge-like appendage on the serialization library to handle this one case. So far no concensus has been reached on how to address this. So a) we can agree that serialization should be on optional add on to any library type and should not require anyone to include serialziation headers if he is not using this facility. This is the case with all current serialization code. b) We prefer that the public interface of a library type be sufficient to implment serialization. This gives the library author the flexibility to alter the implementation without invalidating pre-existing archives. The variant code in question complies with a) above but not b). As far as I know, variant isn't scheduled for inclusion in that standard so this not be a huge issue. On the other hand, I believe that the current variant exposes enough functionality to permit serialization without changes and without exposing any of its implementation. (I might be wrong here). If not, I believe only the smallest of additions to its public interface would be required. So a) we have a working version of variant serialization. I believe it includes a test. b) It might not be what everyone is happy with. I would much like to see progress here as I see serialization of a variant and extremely useful idea which would increase the application of variant. Applications such as transaction logging come to mind. Robert Ramey This would be the normal case. Eric Friedman wrote:
Hi Troy (and others interested in this issue),
When I have some available time, I will take a look at the code for serialization. Sorry for not replying sooner, but I don't check up on the Boost list as often as I should.
One question, as I'm not familiar with the serialization library. What effect do the proposed changes have on those users of variant who do not need/want serialization support? Obviously there is the addition #include, but does this imply overhead, or is the header simply forward declares in the spirit of <iosfwd>?
Thanks,
Eric

Robert Ramey wrote:
The variant code in question complies with a) above but not b). As far as I know, variant isn't scheduled for inclusion in that standard so this not be a huge issue. On the other hand, I believe that the current variant exposes enough functionality to permit serialization without changes and without exposing any of its implementation. (I might be wrong here). If not, I believe only the smallest of additions to its public interface would be required.
OK, I got it. Files attached. No changes to variant, not even a "friend", one header file (boost/serialization/variant.hpp) and an improved test suite. I wish I had looked more closely earlier, now that it is written I see what you were talking about: this is vastly more elegant, about a third as much code, and all in one place. At the moment it was just a rush to get something working, and there was code there. Thanks Peter Dimov for your post with this code:
apply_visitor( bind( variant_saver(), ref(ar), _1 ), v );
which worked practically right out of the box and got me rolling. You know, the further you get into boost the cooler it gets. troy d. straszheim #ifndef BOOST_SERIALIZATION_VARIANT_HPP #define BOOST_SERIALIZATION_VARIANT_HPP // // boost/seriaization/variant.hpp // non-intrusive serialization of variant types // // copyright (c) 2005 // troy d. straszheim <troy@resophonic.com> // http://www.resophonic.com // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org for updates, documentation, and revision history. // // thanks to Robert Ramey and Peter Dimov. // #include <boost/serialization/split_free.hpp> #include <boost/variant/apply_visitor.hpp> #include <boost/bind.hpp> #include <boost/ref.hpp> #include <boost/variant.hpp> #include <boost/variant/static_visitor.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/int.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/eval_if.hpp> #include <boost/mpl/identity.hpp> #include <boost/throw_exception.hpp> #include <boost/archive/archive_exception.hpp> #include <boost/preprocessor/repetition/repeat.hpp> namespace boost { namespace serialization { namespace variant { namespace mpl = boost::mpl; struct save_visitor : boost::static_visitor<> { template<class Archive, class T> void operator()(Archive & ar, T const & value ) const { ar << BOOST_SERIALIZATION_NVP(value); } }; // variant_value_at returns this when we're reading from an // archive and the "which" is at a position that is off the end struct off_the_end_tag { }; // metafunction returns either the type at index i inside type // sequence "types", or off_the_end_tag if i > size<types>. // Needed to avoid instantating load_impl for variant::void_ template <int i, class types> struct variant_value_at { typedef typename mpl::eval_if< typename mpl::greater_equal<mpl::int_<i>, mpl::size<types> >::type , mpl::identity<off_the_end_tag> , mpl::at<types, mpl::int_<i> > >::type type; }; // This loads something of type Value from an archive, when // Value is a "real" value, not variant::void_ template <typename Value> struct load_impl { template <class Archive, typename Variant> inline static void load(Archive& ar, Variant& v) { Value value; ar >> BOOST_SERIALIZATION_NVP(value); v = value; } }; using boost::archive::archive_exception; // This is executed if one tries to load a variant with a long // type sequence into a variant with a shorter type sequence, // e.g. variant<bool,int,short,long> -> variant<bool,int>. We // need to catch this case because calls to this function are // generated for all indices up to BOOST_VARIANT_LIMIT_TYPES, // and we cannot create an object of type variant::void_, which // we must in the primary load_impl template. template<> struct load_impl<off_the_end_tag> { template <class Archive, typename Variant> inline static void load(Archive& ar, Variant& v) { boost::throw_exception(archive_exception(archive_exception::stream_error)); } }; } // namespace boost::serialization::variant #define BOOST_VARIANT_LOADER_CASE_STATEMENT(Z, N, DATA) \ case N: { \ typedef typename \ variant::variant_value_at<N,typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T) \ >::types \ >::type value_t; \ variant::load_impl<value_t>::load(ar, v); \ } break; // somewhere here we have to make the leap from a runtime int to a // compile-time mpl::int_<> so we can dig the value type out of // the variant. Is there a better idiom for this than // preprocessor metaprogramming inside a switch statement? The // switch logic is basically // case 0: do_something_with<type_at_variant_index_0>(); break; // case 1: do_something_with<type_at_variant_index_1>(); break; template <class Archive, BOOST_VARIANT_ENUM_PARAMS(typename T) > inline void load(Archive &ar, boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& v, const unsigned int /* file_version */) { int which; ar >> BOOST_SERIALIZATION_NVP(which); switch(which) { BOOST_PP_REPEAT(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_LOADER_CASE_STATEMENT, unused) } } #undef BOOST_VARIANT_LOADER_CASE_STATEMENT template <class Archive, BOOST_VARIANT_ENUM_PARAMS(typename T) > inline void save(Archive &ar, const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& v, const unsigned int /* file_version */) { int which = v.which(); ar << BOOST_SERIALIZATION_NVP(which); // Suggested by Peter Dimov. Gorgeous, no? apply_visitor( bind( variant::save_visitor(), boost::ref(ar), _1 ), v ); } template <class Archive, BOOST_VARIANT_ENUM_PARAMS(typename T) > inline void serialize(Archive &ar, boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& v, const unsigned int file_version) { boost::serialization::split_free(ar, v, file_version); } } // namespace boost::serialization } // namespace boost #endif // BOOST_SERIALIZATION_VARIANT_HPP // // boost/seriaization/test_variant.cpp // test of non-intrusive serialization of variant types // // copyright (c) 2005 // troy d. straszheim <troy@resophonic.com> // http://www.resophonic.com // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org for updates, documentation, and revision history. // // thanks to Robert Ramey and Peter Dimov. // #include <fstream> #include <cstdio> // remove #include <boost/config.hpp> #if defined(BOOST_NO_STDC_NAMESPACE) namespace std{ using ::remove; } #endif #include "test_tools.hpp" #include <boost/preprocessor/stringize.hpp> #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST) #include <boost/serialization/nvp.hpp> #include "throw_exception.hpp" #include <boost/archive/archive_exception.hpp> #include "A.hpp" #include <boost/serialization/variant.hpp> #include <boost/variant.hpp> #include <boost/variant/apply_visitor.hpp> #include <iostream> template <class T> T archive_and_retrieve(const T& gets_written) { const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(testfile != NULL); { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os); oa << boost::serialization::make_nvp("written", gets_written); } T got_read; { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is); ia >> boost::serialization::make_nvp("written", got_read); } std::remove(testfile); return got_read; } template <class T> void test_type(const T& in) { T out = archive_and_retrieve(in); BOOST_CHECK_EQUAL(in, out); } // // this verifies that if you try to read in a variant from a file // whose "which" is illegal for the one in memory (that is, you're // reading in to a different variant than you wrote out to) the load() // operation will throw. One could concievably add checking for // sequence length as well, but this would add size to the archive for // dubious benefit. // void do_bad_read() { boost::variant<bool, float, int, std::string> big_variant; big_variant = std::string("adrenochrome"); const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(testfile != NULL); { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os); oa << BOOST_SERIALIZATION_NVP(big_variant); } boost::variant<bool, float, int> little_variant; { test_istream is(testfile, TEST_STREAM_FLAGS); test_iarchive ia(is); bool exception_invoked = false; BOOST_TRY { ia >> BOOST_SERIALIZATION_NVP(little_variant); } BOOST_CATCH (boost::archive::archive_exception e) { BOOST_CHECK(boost::archive::archive_exception::stream_error == e.code); exception_invoked = true; } BOOST_CHECK(exception_invoked); } } int test_main( int /* argc */, char* /* argv */[] ) { { boost::variant<bool, int, float, double, A, std::string> v; v = false; test_type(v); v = 1; test_type(v); v = (float) 2.3; test_type(v); v = (double) 6.4; test_type(v); v = std::string("we can't stop here, this is Bat Country"); test_type(v); v = A(); test_type(v); } do_bad_read(); return boost::exit_success; } // EOF

troy d. straszheim wrote:
// the variant. Is there a better idiom for this than // preprocessor metaprogramming inside a switch statement?
There is a better idiom, Richard Crossley sent me a very cool mpl::fold trick. (Thanks Richard!) Improved serialization/variant.hpp attached. troy d. straszheim #ifndef BOOST_SERIALIZATION_VARIANT_HPP #define BOOST_SERIALIZATION_VARIANT_HPP // // boost/seriaization/variant.hpp // non-intrusive serialization of variant types // // copyright (c) 2005 // troy d. straszheim <troy@resophonic.com> // http://www.resophonic.com // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org for updates, documentation, and revision history. // // thanks to Robert Ramey, Peter Dimov, and Richard Crossley. // #include <boost/serialization/serialization.hpp> #include <boost/serialization/split_free.hpp> #include <boost/variant/apply_visitor.hpp> #include <boost/bind.hpp> #include <boost/ref.hpp> #include <boost/variant.hpp> #include <boost/variant/static_visitor.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/int.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/eval_if.hpp> #include <boost/mpl/identity.hpp> #include <boost/throw_exception.hpp> #include <boost/archive/archive_exception.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #include <boost/serialization/split_free.hpp> #include <boost/mpl/fold.hpp> #include <boost/mpl/int.hpp> namespace boost { namespace serialization { namespace variant { struct stop_tag { }; template <typename Value = mpl::void_, typename Base = stop_tag> struct variant_in : Base { enum { index = 1 + Base::index }; template <typename Archive, typename Variant> static void exec(Archive& ar, int discriminator, Variant& var) { if (discriminator == index) { Value value; ar >> BOOST_SERIALIZATION_NVP(value); var = value; return; } Base::exec(ar,discriminator,var); } }; using boost::archive::archive_exception; template <> struct variant_in<mpl::void_, stop_tag> { enum { index = -1 }; template <typename Archive,typename V> static void exec(Archive& ar,int discriminator,V& v) { boost::throw_exception(archive_exception(archive_exception::stream_error)); } }; struct save_visitor : boost::static_visitor<> { template<class Archive, class T> void operator()(Archive & ar, T const & value ) const { ar << BOOST_SERIALIZATION_NVP(value); } }; } // namespace boost::serialization::variant template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> void load(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& v, unsigned int version) { typedef typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types; int which; ar >> BOOST_SERIALIZATION_NVP(which); // fold<> from Richard Crossley. Wicked. The call to exec // starts in the most-derived part of the composite class // generated by fold and recursively works its way down. mpl::fold< types, variant::variant_in<>, variant::variant_in<mpl::_2,mpl::_1> >::type::exec(ar,which,v); } template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> void save(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v, unsigned int version) { int which = v.which(); ar << BOOST_SERIALIZATION_NVP(which); // thx Peter Dimov apply_visitor( bind( variant::save_visitor(), boost::ref(ar), _1 ), v ); } template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> inline void serialize(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v, unsigned int file_version) { split_free(ar,v,file_version); } } } #endif //BOOST_SERIALIZATION_VARIANT_HPP

I reviewed the serialization/variant.hpp. My reaction is: a) Its pretty hard to understand. b) I like it. c) It seems to satisfy all the requirements we wanted. d) I ran the test on my VC 7.1 system and it worked fine e) I made a few cosmetic changes - just to make it look like the rest of serialization code and checked it into CVS Since I made these changes you should check the versions in the main CVS if you want to match up the line numbers. There's still work to be done however - welcome to boost Here is what I get when I try to compile with gcc 3.3: test_variant.cpp Linking to lib file: libboost_serialization-vc6-mt-gd-1_32.lib C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,class boost::_mfi::dm<R,T>,class boost::_bi::list1<class boost::_bi::value<R> > > __cdecl boost::bind(R T::*,A1)' : expects 2 arguments - 3 provided C:\BoostMainCVS\boost/bind.hpp(1501) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> >
__cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(222) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,B8),A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(211) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf7<R,T,B1,B2,B3,B4,B5,B6,B7>,class boost::_bi::list8<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7) const,A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(198) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf7<R,T,B1,B2,B3,B4,B5,B6,B7>,class boost::_bi::list8<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7),A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(187) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf6<R,T,B1,B2,B3,B4,B5,B6>,class boost::_bi::list7<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6) const,A1,A2,A3,A4,A5,A6,A7)' : expects 8 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(174) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf6<R,T,B1,B2,B3,B4,B5,B6>,class boost::_bi::list7<class boost::_bi::value<R>,class boost::_bi::value<R>,class...
Here is what I get when I try to compile with VC 8.0: Run output:../../../libs/serialization/test/test_variant.cpp(58): error in "call_test_main": test gets_written == got_read failed [6.4 != 6.4] *** 1 failure detected in test case "call_test_main" EXIT STATUS: 201 Borland also gives compile errors: Error E2401 C:\BoostMainCVS\boost/variant/detail/substitute_fwd.hpp 50: Invalid template argument list Error E2041 C:\BoostMainCVS\boost/variant/detail/substitute_fwd.hpp 50: Incorrect use of default Error E2040 C:\BoostMainCVS\boost/variant/detail/substitute_fwd.hpp 50: Declaration terminated incorrectly Error E2394 C:\BoostMainCVS\boost/variant/detail/substitute.hpp 101: Too few arguments passed to template 'substitute<T,Dest,Source,Arity>' Error E2040 C:\BoostMainCVS\boost/variant/detail/substitute.hpp 101: Declaration terminated incorrectly Error E2228 C:\BoostMainCVS\boost/variant/detail/substitute.hpp 101: Too many error or warning messages Robert Ramey

So, to summarize, On my machine the results for test_variant are: fail borland 5.51 fail borland 5.64 fail msvc 6 fail VC 8.0 pass VC 7.1 pass gcc 3.3 I'm sure these are issues with other libraries and older compilers rather than the serialization of variant itself. See if you can convince the respective authors to help you on this. Robert Ramey Here is the message for msvc: test_variant.cpp Linking to lib file: libboost_serialization-vc6-mt-gd-1_32.lib C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,class boost::_mfi::dm<R,T>,class boost::_bi::list1<class boost::_bi::value<R> > > __cdecl boost::bind(R T::*,A1)' : expects 2 arguments - 3 provided C:\BoostMainCVS\boost/bind.hpp(1501) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> >
__cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(222) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class boost::_bi::list9<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7,B8),A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(211) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf7<R,T,B1,B2,B3,B4,B5,B6,B7>,class boost::_bi::list8<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7) const,A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(198) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf7<R,T,B1,B2,B3,B4,B5,B6,B7>,class boost::_bi::list8<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6,B7),A1,A2,A3,A4,A5,A6,A7,A8)' : expects 9 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(187) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::cmf6<R,T,B1,B2,B3,B4,B5,B6>,class boost::_bi::list7<class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R> > > __cdecl boost::bind(R (__thiscall T::*)(B1,B2,B3,B4,B5,B6) const,A1,A2,A3,A4,A5,A6,A7)' : expects 8 arguments - 3 provided C:\BoostMainCVS\boost/bind/bind_mf_cc.hpp(174) : see declaration of 'bind' C:\BoostMainCVS\boost/serialization/split_free.hpp(44) : see reference to function template instantiation 'void __cdecl boost::serialization::save(class boost::archive::binary_oarchive &,const class boost::variant<bool,float,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::detail::variant::void4,struct boost::detail::variant::void5,struct boost::detail::variant::void6,struct boost::detail::variant::void7,struct boost::detail::variant::void8,struct boost::detail::variant::void9,struct boost::detail::variant::void10,struct boost::detail::variant::void11,struct boost::detail::variant::void12,struct boost::detail::variant::void13,struct boost::detail::variant::void14,struct boost::detail::variant::void15,struct boost::detail::variant::void16,struct boost::detail::variant::void17,struct boost::detail::variant::void18,struct boost::detail::variant::void19> &,unsigned int)' being compiled C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,struct boost::_mfi::mf6<R,T,B1,B2,B3,B4,B5,B6>,class boost::_bi::list7<class boost::_bi::value<R>,class boost::_bi::value<R>,class... (remainder deleted because of excessive size)

Why use bind here at all? How about just... template<class Archive> struct save_visitor : boost::static_visitor<>{ save_visitor(Archive& ar) : m_ar(&ar) { } template<class T> void operator()(T const & value) const { (*m_ar) << BOOST_SERIALIZATION_NVP(value); } private: Archive* m_ar; }; template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> void save(Archive & ar,boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v,unsigned int version) { int which = v.which(); ar << BOOST_SERIALIZATION_NVP(which); apply_visitor(variant::save_visitor(ar),v); } Regards, Richard.
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: 10 February 2005 05:27 To: boost@lists.boost.org Subject: [boost] Re: Release 1.33 [serialization] [variant]-non-intrusiveversion
So, to summarize,
On my machine the results for test_variant are:
fail borland 5.51 fail borland 5.64 fail msvc 6 fail VC 8.0
pass VC 7.1 pass gcc 3.3
I'm sure these are issues with other libraries and older compilers rather than the serialization of variant itself. See if you can convince the respective authors to help you on this.
Robert Ramey
Here is the message for msvc:
test_variant.cpp Linking to lib file: libboost_serialization-vc6-mt-gd-1_32.lib C:\BoostMainCVS\boost/serialization/variant.hpp(118) : error C2780: 'class boost::_bi::bind_t<R,class boost::_mfi::dm<R,T>,class boost::_bi::list1<class boost::_bi::value<R> > > __cdecl boost::bind(R T::*,A1)' : expects 2 arguments - 3 provided C:\BoostMainCVS\boost/bind.hpp(1501) : see declaration of 'bind'

Richard Crossley wrote:
Why use bind here at all?
I think it's easier to read without it, too. Robert Ramey wrote:
On my machine the results for test_variant are:
fail borland 5.51 fail borland 5.64 fail msvc 6 fail VC 8.0
pass VC 7.1 pass gcc 3.3
I don't have access to any of those failing compilers... Attached is another version that doesn't use bind(), which makes the code essentially what Richard sent me modulo some cosmetic changes. We'd come up with largely the same solution, but Richard totally beat me in the style department. What effect does that have on the problematic compilers? -t #ifndef BOOST_SERIALIZATION_VARIANT_HPP #define BOOST_SERIALIZATION_VARIANT_HPP // // boost/seriaization/variant.hpp // non-intrusive serialization of variant types // // copyright (c) 2005 // troy d. straszheim <troy@resophonic.com> // Richard Crossley <rdc@rdcdesign.com> // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org for updates, documentation, and revision history. // // thanks to Robert Ramey, Peter Dimov. // #include <boost/serialization/serialization.hpp> #include <boost/serialization/split_free.hpp> #include <boost/variant/apply_visitor.hpp> #include <boost/bind.hpp> #include <boost/ref.hpp> #include <boost/variant.hpp> #include <boost/variant/static_visitor.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/int.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/eval_if.hpp> #include <boost/mpl/identity.hpp> #include <boost/throw_exception.hpp> #include <boost/archive/archive_exception.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #include <boost/serialization/split_free.hpp> #include <boost/mpl/fold.hpp> #include <boost/mpl/int.hpp> namespace boost { namespace serialization { namespace variant { struct stop_tag { }; template <typename Value = mpl::void_, typename Base = stop_tag> struct variant_in : Base { enum { index = 1 + Base::index }; template <typename Archive, typename Variant> static void exec(Archive& ar, int discriminator, Variant& var) { if (discriminator == index) { Value value; ar >> BOOST_SERIALIZATION_NVP(value); var = value; return; } Base::exec(ar,discriminator,var); } }; using boost::archive::archive_exception; template <> struct variant_in<mpl::void_, stop_tag> { enum { index = -1 }; template <typename Archive,typename V> static void exec(Archive& ar,int discriminator,V& v) { boost::throw_exception(archive_exception(archive_exception::stream_error)); } }; template<typename Archive> struct save_visitor : static_visitor<> { save_visitor(Archive &ar) : archive_(ar) { } template<typename T> void operator()(T const & value ) const { archive_ << BOOST_SERIALIZATION_NVP(value); } Archive& archive_; }; } // namespace boost::serialization::variant template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> void load(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& v, unsigned int version) { typedef typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types; int which; ar >> BOOST_SERIALIZATION_NVP(which); // fold<> from Richard Crossley. Wicked. The call to exec // starts in the most-derived part of the composite class // generated by fold and recursively works its way down. The // variant gets assigned only when the compile-time Base::index // member of variant_in is equal to the runtime "which". The // trick is: at the level that this condition is satisfied and // the logic fires, the template parameter T of // variant_in<T,Base> is the type we need to create and asssign // to the variant. mpl::fold< types, variant::variant_in<>, variant::variant_in<mpl::_2,mpl::_1> >::type::exec(ar,which,v); } template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> void save(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v, unsigned int version) { int which = v.which(); ar << BOOST_SERIALIZATION_NVP(which); apply_visitor( variant::save_visitor<Archive>(ar), v ); } template<class Archive,BOOST_VARIANT_ENUM_PARAMS(typename T)> inline void serialize(Archive & ar, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v, unsigned int file_version) { split_free(ar,v,file_version); } } } #endif //BOOST_SERIALIZATION_VARIANT_HPP
participants (6)
-
Eric Friedman
-
Francis ANDRE
-
Gennadiy Rozental
-
Richard Crossley
-
Robert Ramey
-
troy d. straszheim