
Hello, I'm looking for a way to serialize a variant. I see two possibly difficult things that I don't know how to accomplish: 1) In order to be able to retrieve a variant from an archive, the type of the value held by the variant must be stored. 2) When retrieving the data from an archive, once the type is read, a value of that type must be extracted from the archive and assigned to the variant. Has anybody tried this before, is this as difficult as it looks? Any help would be greatly appreciated. best regards, Richard Peters

Richard Peters wrote:
Hello,
I'm looking for a way to serialize a variant. I see two possibly difficult things that I don't know how to accomplish: 1) In order to be able to retrieve a variant from an archive, the type of the value held by the variant must be stored. 2) When retrieving the data from an archive, once the type is read, a value of that type must be extracted from the archive and assigned to the variant. Has anybody tried this before, is this as difficult as it looks? Any help would be greatly appreciated.
I would expect the external representation of a variant<T1, ..., Tn> to be: int index; Ti ti; where index denotes the type and is returned by varant<>::which(). Assuming a variant<int, string> for simplicity, the save pseudocode should be something like: int index = v.which(); ar << v; switch( v ) { case 0: ar << get<int>( v ); break; case 1: ar << get<string>( v ); break; } You can rewrite it generically in terms of apply_visitor: struct variant_saver { typedef void result_type; template<class A, class T> void operator( A & a, T const & t ) const { a << t; } }; apply_visitor( bind( variant_saver(), ref(ar), _1 ), v ); Disclaimer: I haven't compiled any of this. ;-) Loading should be the reverse operation: int index; ar >> index; switch( index ) { case 0: { int t; ar << t; v = t; break; } case 1: { string t; ar << t; v = t; break; } } This, of course, belongs in variant.hpp. Don't let our shared_ptr debates fool you. :-)

Basically, this looks OK to me as well. I would like to see it made more automatic and more inline with what other serializations uses. On one level, this is merely a cosmetic issue. On the other level, its about leverage of user interface patterns. Ideally, I would like to see usage something as simple as: Struct X { variant<int, char, unsigned long> x template<class Archive, class T> void serialize(Archive &ar, T& t, unsigned int version){ ar & x; } }; A couple of questions though a) would it not be interesting for variant to return an integer corresponding to is current type? unsigned variant::get_type_index(); b) and the reverse variant::set_type_index(unsigned int ti); // of course this destroys any variable stored therein I would hope this might be implementable. My experience with mpl suggests that it might be. In this case the serialization would be a dream come true. so we could something like: template<class Archive, class T> void save(Archive &ar, const T & v){ usigned int ti = x.get_type_index(); ar << ti apply_visitor( bind( variant_saver(), ref(ar), _1 ), v ); } template<class Archive, class T> void load(Archive &ar, T & v, unsigned int version){ unsigned int ti; ar >> ti; v.set_type_index(ti); apply_visitor( bind( variant_loader(), ref(ar), _1 ), v ); } This would be an example were the type interface can be expanded to better support any serialization implementation without compromising the original design. Just a thought. Robert Ramey "Peter Dimov" <pdimov@mmltd.net> wrote in message news:004401c4d0ad$24160900$6501a8c0@pdimov2...
Richard Peters wrote:
Hello,
I'm looking for a way to serialize a variant. I see two possibly difficult things that I don't know how to accomplish: 1) In order to be able to retrieve a variant from an archive, the type of the value held by the variant must be stored. 2) When retrieving the data from an archive, once the type is read, a value of that type must be extracted from the archive and assigned to the variant. Has anybody tried this before, is this as difficult as it looks? Any help would be greatly appreciated.
I would expect the external representation of a variant<T1, ..., Tn> to be:
int index; Ti ti;
where index denotes the type and is returned by varant<>::which().
Assuming a variant<int, string> for simplicity, the save pseudocode should be something like:
int index = v.which(); ar << v;
switch( v ) { case 0: ar << get<int>( v ); break; case 1: ar << get<string>( v ); break; }
You can rewrite it generically in terms of apply_visitor:
struct variant_saver { typedef void result_type;
template<class A, class T> void operator( A & a, T const & t ) const { a << t; } };
apply_visitor( bind( variant_saver(), ref(ar), _1 ), v );
Disclaimer: I haven't compiled any of this. ;-)
Loading should be the reverse operation:
int index; ar >> index;
switch( index ) { case 0: { int t; ar << t; v = t; break; } case 1: { string t; ar << t; v = t; break; } }
This, of course, belongs in variant.hpp. Don't let our shared_ptr debates fool you. :-)
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"Robert Ramey" <ramey@rrsd.com> wrote in message news:cnt6jr$m32$1@sea.gmane.org...
Basically, this looks OK to me as well. I would like to see it made more automatic and more inline with what other serializations uses. On one level, this is merely a cosmetic issue. On the other level, its about leverage of user interface patterns. Ideally, I would like to see usage something as simple as:
Struct X { variant<int, char, unsigned long> x template<class Archive, class T> void serialize(Archive &ar, T& t, unsigned int version){ ar & x; } };
A couple of questions though
a) would it not be interesting for variant to return an integer corresponding to is current type? unsigned variant::get_type_index();
What about "int variant::which()" ?
b) and the reverse variant::set_type_index(unsigned int ti); // of course this destroys any variable stored therein
I would hope this might be implementable. My experience with mpl suggests that it might be. In this case the serialization would be a dream come true.
so we could something like: template<class Archive, class T> void save(Archive &ar, const T & v){ usigned int ti = x.get_type_index(); ar << ti apply_visitor( bind( variant_saver(), ref(ar), _1 ), v ); }
template<class Archive, class T> void load(Archive &ar, T & v, unsigned int version){ unsigned int ti; ar >> ti; v.set_type_index(ti); apply_visitor( bind( variant_loader(), ref(ar), _1 ), v ); }
The above would be nice indeed. I've also been deserializing variants and wondered if there was any another way to do it - this would definitely make things easier. // Johan

"Johan Nilsson" <johan.nilsson@esrange.ssc.se> wrote in message news:cnvd54$uch$1@sea.gmane.org...
"Robert Ramey" <ramey@rrsd.com> wrote in message news:cnt6jr$m32$1@sea.gmane.org...
Basically, this looks OK to me as well. I would like to see it made more automatic and more inline with what other serializations uses. On one level, this is merely a cosmetic issue. On the other level, its about leverage of user interface patterns.
I have implemented a different type of visitor for variant: one that does not take the current value held by a variant into account, but a given index. The visitor then calls the visit object with a null pointer of the type of the index-th argument of variant. This is then used by a serializer to extract a value of that type, and assign it to the variant. Attached are two diff files, one for variant.hpp and one for detail/visitation_impl.hpp, which implement the different visitor and all associated functions, which all have 'param' attached somewhere in their name -- apply_param_visitor, internal_apply_param_visitor_impl, param_visitation_impl_invoke_impl, etc. The serialization is also integrated into variant. I do not know if the authors want this in this place, but it is just a solution that works. Also attached is an example file to demonstrate that it works. Oh and I'd like to take the opportunity to thank both the authors of boost.variant and boost.serialization, these libraries will make my life much easier in my current project. best regards, Richard Peters begin 666 variant.hpp.diff M-#,L-#5D-#(-"CP@(VEN8VQU9&4@(F)O;W-T+W-E<FEA;&EZ871I;VXO86-C M97-S+FAP<"(-"CP@(VEN8VQU9&4@(F)O;W-T+W-E<FEA;&EZ871I;VXO;G9P M+FAP<"(-"CP@(VEN8VQU9&4@(F)O;W-T+W-E<FEA;&EZ871I;VXO<W!L:71? M;65M8F5R+FAP<"(-"C@Y.2PY-C%D.#DU#0H\('1E;7!L871E(#QT>7!E;F%M M92!6:7-I=&]R/@T*/"!C;&%S<R!I;G9O:V5?<&%R86U?=FES:71O<@T*/"![ M#0H\('!R:79A=&4Z("\O(')E<')E<V5N=&%T:6]N#0H\( T*/" @(" @5FES M:71O<B8@=FES:71O<E\[#0H\( T*/"!P=6)L:6,Z("\O('9I<VET;W(@='EP M961E9G,-"CP@#0H\(" @("!T>7!E9&5F('1Y<&5N86UE(%9I<VET;W(Z.G)E M<W5L=%]T>7!E#0H\(" @(" @(" @<F5S=6QT7W1Y<&4[#0H\( T*/"!P=6)L M:6,Z("\O('-T<G5C=&]R<PT*/" -"CP@(" @(&5X<&QI8VET(&EN=F]K95]P M87)A;5]V:7-I=&]R*%9I<VET;W(F('9I<VET;W(I#0H\(" @(" @(" @.B!V M:7-I=&]R7RAV:7-I=&]R*0T*/" @(" @>PT*/" @(" @?0T*/" -"CP@(VEF M("%D969I;F5D*$)/3U-47TY/7U9/241?4D5455).4RD-"CP@#0H\('!U8FQI M8SH@+R\@:6YT97)N86P@=FES:71O<B!I;G1E<F9A8V5S#0H\( T*/" @(" @ M=&5M<&QA=&4@/'1Y<&5N86UE(%0^#0H\(" @("!R97-U;'1?='EP92!I;G1E M<FYA;%]V:7-I="A4*BP@:6YT*0T*/" @(" @>PT*/" @(" @(" @(')E='5R M;B!V:7-I=&]R7RAS=&%T:6-?8V%S=#Q4*CXH,"DI.PT*/" @(" @?0T*/" - M"CP@(V5L<V4@+R\@9&5F:6YE9"A"3T]35%].3U]63TE$7U)%5%523E,I#0H\ M( T*/"!P<FEV871E.B O+R!H96QP97)S+"!F;W(@:6YT97)N86P@=FES:71O M<B!I;G1E<F9A8V5S("AB96QO=RD-"CP@#0H\(" @("!T96UP;&%T92 \='EP M96YA;64@5#X-"CP@(" @(" @("!"3T]35%]605))04Y47T%56%]'14Y%4DE# M7U)%4U5,5%]465!%*')E<W5L=%]T>7!E*0T*/" @(" @=FES:71?:6UP;"A4 M*BP@;7!L.CIF86QS95\I#0H\(" @("![#0H\(" @(" @(" @<F5T=7)N('9I M<VET;W)?*'-T871I8U]C87-T/%0J/B@P*2D[#0H\(" @("!]#0H\( T*/" @ M(" @=&5M<&QA=&4@/'1Y<&5N86UE(%0^#0H\(" @(" @(" @0D]/4U1?5D%2 M24%.5%]!55A?4D5455).7U9/241?5%E010T*/" @(" @=FES:71?:6UP;"A4 M*BP@;7!L.CIT<G5E7RD-"CP@(" @('L-"CP@(" @(" @("!V:7-I=&]R7RAS M=&%T:6-?8V%S=#Q4*CXH,"DI.PT*/" @(" @(" @($)/3U-47U9!4DE!3E1? M05587U)%5%523E]63TE$.PT*/" @(" @?0T*/" -"CP@<'5B;&EC.B O+R!I M;G1E<FYA;"!V:7-I=&]R(&EN=&5R9F%C97,-"CP@#0H\(" @("!T96UP;&%T M92 \='EP96YA;64@5#X-"CP@(" @(" @("!"3T]35%]605))04Y47T%56%]' M14Y%4DE#7U)%4U5,5%]465!%*')E<W5L=%]T>7!E*0T*/" @(" @:6YT97)N M86Q?=FES:70H5"HL(&EN="D-"CP@(" @('L-"CP@(" @(" @("!T>7!E9&5F M('1Y<&5N86UE(&ES7W-A;64\<F5S=6QT7W1Y<&4L('9O:60^.CIT>7!E#0H\ M(" @(" @(" @(" @(&AA<U]V;VED7W)E<W5L=%]T>7!E.PT*/" -"CP@(" @ M(" @("!R971U<FX@=FES:71?:6UP;"AS=&%T:6-?8V%S=#Q4*CXH,"DL(&AA M<U]V;VED7W)E<W5L=%]T>7!E*"DI.PT*/" @(" @?0T*/" -"CP@(V5N9&EF M("\O($)/3U-47TY/7U9/241?4D5455).4RD@=V]R:V%R;W5N9 T*/"!].PT* M/" -"C$X,#@L,3@S,F0Q-S0Q#0H\(" @("!S=&%T:6,-"CP@(" @(" @("!" M3T]35%]605))04Y47T%56%]'14Y%4DE#7U)%4U5,5%]465!%* T*/" @(" @ M(" @(" @(" @('1Y<&5N86UE(%9I<VET;W(Z.G)E<W5L=%]T>7!E#0H\(" @ M(" @(" @(" @("D-"CP@(" @(&EN=&5R;F%L7V%P<&QY7W!A<F%M7W9I<VET M;W)?:6UP;"@-"CP@(" @(" @(" @(&EN="!L;V=I8V%L7W=H:6-H#0H\(" @ M(" @(" @+"!6:7-I=&]R)B!V:7-I=&]R#0H\(" @(" @(" @*0T*/" @(" @ M>PT*/" @(" @(" @('1Y<&5D968@;7!L.CII;G1?/# ^(&9I<G-T7W=H:6-H M.PT*/" @(" @(" @('1Y<&5D968@='EP96YA;64@;7!L.CIB96=I;CQI;G1E M<FYA;%]T>7!E<SXZ.G1Y<&4@9FER<W1?:70[#0H\(" @(" @(" @='EP961E M9B!T>7!E;F%M92!M<&PZ.F5N9#QI;G1E<FYA;%]T>7!E<SXZ.G1Y<&4@;&%S M=%]I=#L-"CP@#0H\(" @(" @(" @='EP961E9B!D971A:6PZ.G9A<FEA;G0Z M.G9I<VET871I;VY?:6UP;%]S=&5P/ T*/" @(" @(" @(" @(" @(&9I<G-T M7VET+"!L87-T7VET#0H\(" @(" @(" @(" @(#X@9FER<W1?<W1E<#L-"CP@ M#0H\(" @(" @(" @<F5T=7)N(&1E=&%I;#HZ=F%R:6%N=#HZ<&%R86U?=FES M:71A=&EO;E]I;7!L* T*/" @(" @(" @(" @(" @(&QO9VEC86Q?=VAI8V@- M"CP@(" @(" @(" @(" @+"!V:7-I=&]R+"!M<&PZ.F9A;'-E7R@I#0H\(" @ M(" @(" @(" @("P@<W1A=&EC7V-A<W0\9FER<W1?=VAI8V@J/B@P*2P@<W1A M=&EC7V-A<W0\9FER<W1?<W1E<"H^*# I#0H\(" @(" @(" @(" @("D[#0H\ M(" @("!]#0H\( T*/" @(" @=&5M<&QA=&4@/'1Y<&5N86UE(%9I<VET;W(^ M#0HQ.#4T+#$X-S5D,3<V,@T*/" @(" @=&5M<&QA=&4@/'1Y<&5N86UE(%9I M<VET;W(^#0H\(" @(" @(" @0D]/4U1?5D%224%.5%]!55A?1T5.15))0U]2 M15-53%1?5%E012@-"CP@(" @(" @(" @(" @("!T>7!E;F%M92!6:7-I=&]R M.CIR97-U;'1?='EP90T*/" @(" @(" @(" @(" I#0H\(" @("!I;G1E<FYA M;%]A<'!L>5]P87)A;5]V:7-I=&]R*%9I<VET;W(F('9I<VET;W(L(&EN="!P M87)A;2D-"CP@(" @('L-"CP@(" @(" @("!R971U<FX@:6YT97)N86Q?87!P M;'E?<&%R86U?=FES:71O<E]I;7!L* T*/" @(" @(" @(" @(" @('!A<F%M M+"!V:7-I=&]R#0H\(" @(" @(" @(" @("D[#0H\(" @("!]#0H\( T*/" @ M(" @=&5M<&QA=&4@/'1Y<&5N86UE(%9I<VET;W(^#0H\(" @(" @(" @0D]/ M4U1?5D%224%.5%]!55A?1T5.15))0U]215-53%1?5%E012@-"CP@(" @(" @ M(" @(" @("!T>7!E;F%M92!6:7-I=&]R.CIR97-U;'1?='EP90T*/" @(" @ M(" @(" @(" I#0H\(" @("!I;G1E<FYA;%]A<'!L>5]P87)A;5]V:7-I=&]R M*%9I<VET;W(F('9I<VET;W(L(&EN="!P87)A;2D@8V]N<W0-"CP@(" @('L- M"CP@(" @(" @("!R971U<FX@:6YT97)N86Q?87!P;'E?<&%R86U?=FES:71O M<E]I;7!L* T*/" @(" @(" @(" @(" @('!A<F%M+"!V:7-I=&]R#0H\(" @ M(" @(" @(" @("D[#0H\(" @("!]#0H\( T*,3@Y."PQ.3<P9#$W.#0-"CP@ M(" @('1E;7!L871E(#QT>7!E;F%M92!6:7-I=&]R/@T*/" @(" @(" @($)/ M3U-47U9!4DE!3E1?05587T=%3D5224-?4D5354Q47U194$4H#0H\(" @(" @ M(" @(" @(" @='EP96YA;64@5FES:71O<CHZ<F5S=6QT7W1Y<&4-"CP@(" @ M(" @(" @(" @*0T*/" @(" @87!P;'E?<&%R86U?=FES:71O<BA6:7-I=&]R M)B!V:7-I=&]R+"!I;G0@<&%R86TI#0H\(" @("![#0H\(" @(" @(" @9&5T M86EL.CIV87)I86YT.CII;G9O:V5?<&%R86U?=FES:71O<CQ6:7-I=&]R/B!I M;G9O:V5R*'9I<VET;W(I.PT*/" @(" @(" @(')E='5R;B!T:&ES+3YI;G1E M<FYA;%]A<'!L>5]P87)A;5]V:7-I=&]R*&EN=F]K97(L('!A<F%M*3L-"CP@ M(" @('T-"CP@#0H\(" @("!T96UP;&%T92 \='EP96YA;64@5FES:71O<CX- M"CP@(" @(" @("!"3T]35%]605))04Y47T%56%]'14Y%4DE#7U)%4U5,5%]4 M65!%* T*/" @(" @(" @(" @(" @('1Y<&5N86UE(%9I<VET;W(Z.G)E<W5L M=%]T>7!E#0H\(" @(" @(" @(" @("D-"CP@(" @(&%P<&QY7W!A<F%M7W9I M<VET;W(H5FES:71O<B8@=FES:71O<BP@:6YT('!A<F%M*2!C;VYS= T*/" @ M(" @>PT*/" @(" @(" @(&1E=&%I;#HZ=F%R:6%N=#HZ:6YV;VME7W!A<F%M M7W9I<VET;W(\5FES:71O<CX@:6YV;VME<BAV:7-I=&]R*3L-"CP@(" @(" @ M("!R971U<FX@=&AI<RT^:6YT97)N86Q?87!P;'E?<&%R86U?=FES:71O<BAI M;G9O:V5R+"!P87)A;2D[#0H\(" @("!]#0H\( T*/"!P<FEV871E.@T*/" @ M(" @=&5M<&QA=&4\8VQA<W,@07)C:&EV93X-"CP@(" @(&-L87-S('-T;W)E M7V%R8VAI=F4Z('!U8FQI8R!S=&%T:6-?=FES:71O<CQV;VED/@T*/" @(" @ M>PT*/" @(" @(" @($%R8VAI=F4F(&%R8VAI=F4[#0H\(" @("!P=6)L:6,Z M#0H\(" @(" @(" @<W1O<F5?87)C:&EV92A!<F-H:79E)B!A<BD-"CP@(" @ M(" @(" @(" @.B!A<F-H:79E*&%R*2![?0T*/" -"CP@(" @(" @("!T96UP M;&%T93QC;&%S<R!4/@T*/" @(" @(" @('9O:60@;W!E<F%T;W(H*2A4('9A M;'5E*2!C;VYS= T*/" @(" @(" @('L-"CP@(" @(" @(" @(" @87)C:&EV M92 F($)/3U-47U-%4DE!3$E:051)3TY?3E90*'9A;'5E*3L-"CP@(" @(" @ M("!]#0H\(" @("!].PT*/" -"CP@(" @('1E;7!L871E/&-L87-S($%R8VAI M=F4^#0H\(" @("!C;&%S<R!L;V%D7V%R8VAI=F4Z('!U8FQI8R!S=&%T:6-? M=FES:71O<CQV;VED/@T*/" @(" @>PT*/" @(" @(" @($%R8VAI=F4F(&%R M8VAI=F4[#0H\(" @(" @(" @=F%R:6%N="8@9&5S=&EN871I;VX[#0H\(" @ M("!P=6)L:6,Z#0H\(" @(" @(" @;&]A9%]A<F-H:79E*$%R8VAI=F4F(&%R M+"!V87)I86YT)B!V87(I#0H\(" @(" @(" @(" @(#H@87)C:&EV92AA<BDL M(&1E<W1I;F%T:6]N*'9A<BD@>WT-"CP@#0H\(" @(" @(" @=&5M<&QA=&4\ M8VQA<W,@5#X-"CP@(" @(" @("!V;VED(&]P97)A=&]R*"DH5"HI(&-O;G-T M#0H\(" @(" @(" @>PT*/" @(" @(" @(" @("!4('9A;'5E.PT*/" @(" @ M(" @(" @("!A<F-H:79E("8@0D]/4U1?4T5224%,25I!5$E/3E].5E H=F%L M=64I.PT*/" @(" @(" @(" @("!D97-T:6YA=&EO;B ]('9A;'5E.PT*/" @ M(" @(" @('T-"CP@(" @('T[#0H\( T*/" @(" @9G)I96YD(&-L87-S(&)O M;W-T.CIS97)I86QI>F%T:6]N.CIA8V-E<W,[#0H\( T*/" @(" @=&5M<&QA M=&4\8VQA<W,@07)C:&EV93X-"CP@(" @('9O:60@<V%V92A!<F-H:79E("8@ M87(L(&-O;G-T('5N<VEG;F5D(&EN="!V97)S:6]N*2!C;VYS= T*/" @(" @ M>PT*/" @(" @(" @(&EN="!W:&EC:%]A<F=U;65N="AW:&EC:"@I*3L-"CP@ M(" @(" @("!A<B F(&)O;W-T.CIS97)I86QI>F%T:6]N.CIM86ME7VYV<"@B M=VAI8V@B+"!W:&EC:%]A<F=U;65N="D[#0H\(" @(" @(" @87!P;'E?=FES M:71O<BAS=&]R95]A<F-H:79E/$%R8VAI=F4^*&%R*2D[#0H\(" @("!]#0H\ M( T*/" @(" @=&5M<&QA=&4\8VQA<W,@07)C:&EV93X-"CP@(" @('9O:60@ M;&]A9"A!<F-H:79E("8@87(L(&-O;G-T('5N<VEG;F5D(&EN="!V97)S:6]N M*0T*/" @(" @>PT*/" @(" @(" @(&EN="!W:&EC:%]A<F=U;65N=#L-"CP@ M(" @(" @("!A<B F(&)O;W-T.CIS97)I86QI>F%T:6]N.CIM86ME7VYV<"@B M=VAI8V@B+"!W:&EC:%]A<F=U;65N="D[#0H\(" @(" @(" @87!P;'E?<&%R M86U?=FES:71O<BAL;V%D7V%R8VAI=F4\07)C:&EV93XH87(L("IT:&ES*2P@ M=VAI8VA?87)G=6UE;G0I.PT*/" @(" @?0T*/" -"CP@(" @($)/3U-47U-% <4DE!3$E:051)3TY?4U!,251?345-0D52*"D-"@`` ` end begin 666 variant_serialization.cpp M(VEN8VQU9&4@/&)O;W-T+W9A<FEA;G0N:'!P/@T*(VEN8VQU9&4@/&)O;W-T M+W-E<FEA;&EZ871I;VXO<W!L:71?;65M8F5R+FAP<#X-"B-I;F-L=61E(#QB M;V]S="]A<F-H:79E+WAM;%]O87)C:&EV92YH<' ^#0HC:6YC;'5D92 \8F]O M<W0O87)C:&EV92]X;6Q?:6%R8VAI=F4N:'!P/@T*(VEN8VQU9&4@/&EO<W1R M96%M/@T*(VEN8VQU9&4@/'-S=')E86T^#0H-"F-L87-S('!R:6YT7W9I<VET M;W(Z('!U8FQI8R!B;V]S=#HZ<W1A=&EC7W9I<VET;W(\=F]I9#X-"GL-"G!U M8FQI8SH-"B @("!T96UP;&%T93QC;&%S<R!4/@T*(" @(" @("!V;VED(&]P M97)A=&]R*"DH5"!V86QU92D@8V]N<W0-"B @("![#0H@(" @(" @('-T9#HZ M8V]U=" \/"!V86QU92 \/"!S=&0Z.F5N9&P[#0H@(" @?0T*?3L-"@T*:6YT M(&UA:6XH*2![#0H@(" @<W1D.CIS=')I;F<@=F%L=64@/2 B8FQA:"([#0H@ M(" @+R]I;G0@=F%L=64@/2 U.PT*(" @(&)O;W-T.CIV87)I86YT/&EN="P@ M<W1D.CIS=')I;F<^('@@/2!V86QU93L-"@T*(" @('-T9#HZ;W-T<FEN9W-T M<F5A;2!O<W,[#0H@(" @8F]O<W0Z.F%R8VAI=F4Z.GAM;%]O87)C:&EV92!O M82AO<W,I.PT*(" @(&]A(#P\($)/3U-47U-%4DE!3$E:051)3TY?3E90*'@I M.PT*#0H@(" @<W1D.CIC;W5T(#P\(&]S<RYS='(H*2 \/"!S=&0Z.F5N9&P[ M#0H-"B @("!S=&0Z.FES=')I;F=S=')E86T@:7-S*&]S<RYS='(H*2D[#0H@ M(" @8F]O<W0Z.F%R8VAI=F4Z.GAM;%]I87)C:&EV92!I82AI<W,I.PT*#0H@ M(" @8F]O<W0Z.G9A<FEA;G0\:6YT+"!S=&0Z.G-T<FEN9SX@;F5W>#L-"B @ M("!I82 ^/B!"3T]35%]315))04Q)6D%424].7TY64"AN97=X*3L-"@T*(" @ M(&)O;W-T.CIA<'!L>5]V:7-I=&]R*'!R:6YT7W9I<VET;W(H*2P@;F5W>"D[ 6#0H-"B @("!R971U<FX@,#L-"GT-"@`` ` end begin 666 visitation_impl.hpp.diff M,34Q+#$V,F0Q-3 -"CP@=&5M<&QA=&4@/'1Y<&5N86UE(%9I<VET;W(L('1Y M<&5N86UE(%0^#0H\(&EN;&EN90T*/" @(" @0D]/4U1?5D%224%.5%]!55A? M1T5.15))0U]215-53%1?5%E012AT>7!E;F%M92!6:7-I=&]R.CIR97-U;'1? M='EP92D-"CP@<&%R86U?=FES:71A=&EO;E]I;7!L7VEN=F]K95]I;7!L* T* M/" @(" @("!6:7-I=&]R)B!V:7-I=&]R+"!4*@T*/" @(" @*0T*/"![#0H\ M(" @("!R971U<FX@=FES:71O<BYI;G1E<FYA;%]V:7-I="@-"CP@(" @(" @ M(" @('-T871I8U]C87-T/%0J/B@P*2P@,4P-"CP@(" @(" @(" I.PT*/"!] M#0H\( T*,3DU+#(Q-V0Q.#(-"CP@=&5M<&QA=&4@/'1Y<&5N86UE(%9I<VET M;W(L('1Y<&5N86UE(%0^#0H\(&EN;&EN90T*/" @(" @0D]/4U1?5D%224%. M5%]!55A?1T5.15))0U]215-53%1?5%E012AT>7!E;F%M92!6:7-I=&]R.CIR M97-U;'1?='EP92D-"CP@<&%R86U?=FES:71A=&EO;E]I;7!L7VEN=F]K92@- M"CP@(" @(" @5FES:71O<B8@=FES:71O<BP@5"H@= T*/" @(" @*0T*/"![ M#0H\(" @("!R971U<FX@<&%R86U?=FES:71A=&EO;E]I;7!L7VEN=F]K95]I M;7!L* T*/" @(" @(" @(" @=FES:71O<BP@= T*/" @(" @(" @("D[#0H\ M('T-"CP@#0H\('1E;7!L871E(#QT>7!E;F%M92!6:7-I=&]R/@T*/"!I;FQI M;F4-"CP@(" @($)/3U-47U9!4DE!3E1?05587T=%3D5224-?4D5354Q47U19 M4$4H='EP96YA;64@5FES:71O<CHZ<F5S=6QT7W1Y<&4I#0H\('!A<F%M7W9I M<VET871I;VY?:6UP;%]I;G9O:V4H5FES:71O<B8L(&%P<&QY7W9I<VET;W)? M=6YR;VQL960J*0T*/"![#0H\(" @(" O+R!S:&]U;&0@;F5V97(@8F4@:&5R M92!A="!R=6YT:6UE.@T*/" @(" @0D]/4U1?05-315)4*&9A;'-E*3L-"CP@ M(" @('1Y<&5D968@='EP96YA;64@5FES:71O<CHZ<F5S=6QT7W1Y<&4@<F5S M=6QT7W1Y<&4[#0H\(" @("!R971U<FX@.CIB;V]S=#HZ9&5T86EL.CIV87)I M86YT.CIF;W)C961?<F5T=7)N/"!R97-U;'1?='EP92 ^*"D[#0H\('T-"CP@ M#0HS,30L-# R9#(W. T*/" @(" @(" @("P@<W1A=&EC7V-A<W0\;F5X=%]W M:&EC:"H^*# I+"!S=&%T:6-?8V%S=#QN97AT7W-T97 J/B@P*0T*/" @(" @ M(" @("D[#0H\('T-"CP@#0H\('1E;7!L871E(#P-"CP@(" @(" @='EP96YA M;64@5RP@='EP96YA;64@4PT*/" @(" @+"!T>7!E;F%M92!6:7-I=&]R#0H\ M(" @(" ^#0H\(&EN;&EN90T*/" @(" @0D]/4U1?5D%224%.5%]!55A?1T5. M15))0U]215-53%1?5%E012AT>7!E;F%M92!6:7-I=&]R.CIR97-U;'1?='EP M92D-"CP@<&%R86U?=FES:71A=&EO;E]I;7!L* T*/" @(" @("!I;G0L(%9I M<VET;W(F#0H\(" @(" L(&UP;#HZ=')U95\@+R\@:7-?87!P;'E?=FES:71O M<E]U;G)O;&QE9 T*/" @(" @+"!7*B ](# L(%,J(#T@, T*/" @(" @*0T* M/"![#0H\(" @(" O+R!S:&]U;&0@;F5V97(@8F4@:&5R92!A="!R=6YT:6UE M.@T*/" @(" @0D]/4U1?05-315)4*&9A;'-E*3L-"CP@(" @('1Y<&5D968@ M='EP96YA;64@5FES:71O<CHZ<F5S=6QT7W1Y<&4@<F5S=6QT7W1Y<&4[#0H\ M(" @("!R971U<FX@.CIB;V]S=#HZ9&5T86EL.CIV87)I86YT.CIF;W)C961? M<F5T=7)N/"!R97-U;'1?='EP92 ^*"D[#0H\('T-"CP@#0H\('1E;7!L871E M(#P-"CP@(" @(" @='EP96YA;64@5VAI8V@L('1Y<&5N86UE('-T97 P#0H\ M(" @(" L('1Y<&5N86UE(%9I<VET;W(-"CP@(" @(#X-"CP@:6YL:6YE#0H\ M(" @("!"3T]35%]605))04Y47T%56%]'14Y%4DE#7U)%4U5,5%]465!%*'1Y M<&5N86UE(%9I<VET;W(Z.G)E<W5L=%]T>7!E*0T*/"!P87)A;5]V:7-I=&%T M:6]N7VEM<&PH#0H\(" @(" @(&-O;G-T(&EN="!L;V=I8V%L7W=H:6-H#0H\ M(" @(" L(%9I<VET;W(F('9I<VET;W(-"CP@(" @("P@;7!L.CIF86QS95\@ M+R\@:7-?87!P;'E?=FES:71O<E]U;G)O;&QE9 T*/" @(" @+"!7:&EC:"H@ M/2 P+"!S=&5P,"H@/2 P#0H\(" @(" I#0H\('L-"CP@(" @("\O(%1Y<&5D M968@87!P;'E?=FES:71O<E]U;G)O;&QE9"!S=&5P<R!A;F0@87-S;V-I871E M9"!T>7!E<RXN+@T*/" C(" @9&5F:6YE($)/3U-47U9!4DE!3E1?05587T%0 M4$Q97U9)4TE43U)?4U1%4%]465!%1$5&*'HL($XL(%\I(%P-"CP@(" @('1Y M<&5D968@='EP96YA;64@0D]/4U1?4%!?0T%4*'-T97 L3BDZ.G1Y<&4@0D]/ M4U1?4%!?0T%4*%0L3BD[(%P-"CP@(" @('1Y<&5D968@='EP96YA;64@0D]/ M4U1?4%!?0T%4*'-T97 L3BDZ.FYE>'0@7 T*/" @(" @(" @($)/3U-47U!0 M7T-!5"AS=&5P+"!"3T]35%]04%])3D,H3BDI.R!<#0H\(" @(" O*BHO#0H\ M( T*/" @(" @0D]/4U1?4%!?4D5014%4* T*/" @(" @(" @(" @0D]/4U1? M5D%224%.5%]625-)5$%424].7U5.4D],3$E.1U],24U)5 T*/" @(" @(" @ M("P@0D]/4U1?5D%224%.5%]!55A?05!03%E?5DE3251/4E]35$507U194$5$ M148-"CP@(" @(" @(" L(%\-"CP@(" @(" @(" I#0H\( T*/" C(" @=6YD M968@0D]/4U1?5D%224%.5%]!55A?05!03%E?5DE3251/4E]35$507U194$5$ M148-"CP@#0H\(" @(" O+R N+BYS=VET8V@@;VX@=&AE('1A<F=E="!W:&EC M:"UI;F1E>"!V86QU92XN+@T*/" @(" @<W=I=&-H("AL;V=I8V%L7W=H:6-H M*0T*/" @(" @>PT*/" -"CP@(" @("\O("XN+F%P<&QY:6YG('1H92!A<'!R M;W!R:6%T92!C87-E.@T*/" C(" @9&5F:6YE($)/3U-47U9!4DE!3E1?0558 M7T%04$Q97U9)4TE43U)?4U1%4%]#05-%*'HL($XL(%\I(%P-"CP@(" @(&-A M<V4@*%=H:6-H.CIV86QU92 K("A.*2DZ(%P-"CP@(" @(" @("!R971U<FX@ M<&%R86U?=FES:71A=&EO;E]I;7!L7VEN=F]K92@@7 T*/" @(" @(" @(" @ M(" @('9I<VET;W)<#0H\(" @(" @(" @(" @("P@<W1A=&EC7V-A<W0\0D]/ M4U1?4%!?0T%4*%0L3BDJ/B@P*2!<#0H\(" @(" @(" @(" @("D[(%P-"CP@ M(" @("\J*B\-"CP@#0H\(" @("!"3T]35%]04%]215!%050H#0H\(" @(" @ M(" @("!"3T]35%]605))04Y47U9)4TE4051)3TY?54Y23TQ,24Y'7TQ)34E4 M#0H\(" @(" @(" @+"!"3T]35%]605))04Y47T%56%]!4%!,65]625-)5$]2 M7U-415!?0T%310T*/" @(" @(" @("P@7PT*/" @(" @(" @("D-"CP@#0H\ M(",@("!U;F1E9B!"3T]35%]605))04Y47T%56%]!4%!,65]625-)5$]27U-4 M15!?0T%310T*/" -"CP@(" @('T-"CP@#0H\(" @(" O+R!)9B!N;W0@:&%N M9&QE9"!I;B!T:&ES(&ET97)A=&EO;BP@8V]N=&EN=64@=6YR;VQL:6YG.@T* M/" @(" @='EP961E9B!M<&PZ.FEN=%\\#0H\(" @(" @(" @("!7:&EC:#HZ M=F%L=64@*R H0D]/4U1?5D%224%.5%]625-)5$%424].7U5.4D],3$E.1U], M24U)5"D-"CP@(" @(" @(" ^(&YE>'1?=VAI8V@[#0H\( T*/" @(" @='EP M961E9B!"3T]35%]04%]#050H<W1E<"P@0D]/4U1?5D%224%.5%]625-)5$%4 M24].7U5.4D],3$E.1U],24U)5"D-"CP@(" @(" @("!N97AT7W-T97 [#0H\ M( T*/" @(" @='EP961E9B!T>7!E;F%M92!N97AT7W-T97 Z.G1Y<&4@;F5X M=%]T>7!E.PT*/" @(" @='EP961E9B!T>7!E;F%M92!I<U]S86UE/"!N97AT M7W1Y<&4L87!P;'E?=FES:71O<E]U;G)O;&QE9" ^.CIT>7!E#0H\(" @(" @ M(" @:7-?87!P;'E?=FES:71O<E]U;G)O;&QE9#L-"CP@#0H\(" @("!R971U M<FX@<&%R86U?=FES:71A=&EO;E]I;7!L* T*/" @(" @(" @(" @;&]G:6-A M;%]W:&EC: T*/" @(" @(" @("P@=FES:71O<@T*/" @(" @(" @("P@:7-? :87!P;'E?=FES:71O<E]U;G)O;&QE9"@I#0H` ` end

"Richard Peters" <r.a.peters@student.tue.nl> wrote in message news:co291u$68j$1@sea.gmane.org...
I have implemented a different type of visitor for variant: one that does not take the current value held by a variant into account, but a given index. The visitor then calls the visit object with a null pointer of the type of the index-th argument of variant. This is then used by a serializer to extract a value of that type, and assign it to the variant.
Attached are two diff files, one for variant.hpp and one for detail/visitation_impl.hpp, which implement the different visitor and all associated functions, which all have 'param' attached somewhere in their name -- apply_param_visitor, internal_apply_param_visitor_impl, param_visitation_impl_invoke_impl, etc. The serialization is also integrated into variant. I do not know if the authors want this in this place, but it is just a solution that works.
Also attached is an example file to demonstrate that it works.
Oh and I'd like to take the opportunity to thank both the authors of boost.variant and boost.serialization, these libraries will make my life much easier in my current project.
I realize now that I didn't describe what problem I solved. Oops. 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. best regards, Richard Peters

I've implemented a de/serialization of variant using an extended version of the "bencode" format from the BitTorrent protocol (see http://bittorrent.com/protocol.html for more details). I've extended it to include the Boost gregorian date and posix_time types from the date_time library. Basically, there is a single character type specifier before each value that you can use to trigger type-specific handling. Attached are an implementation and an example program that exercises the implementation as well as the new assign library (with a more American style of football score :) -- Caleb Epstein caleb dot epstein at gmail dot com
participants (5)
-
Caleb Epstein
-
Johan Nilsson
-
Peter Dimov
-
Richard Peters
-
Robert Ramey