|
Boost : |
From: Vaclav Vesely (vaclav.vesely_at_[hidden])
Date: 2006-10-06 04:20:32
Hi,
I would like to do somethink like this:
class Base {...}
class Derived: public Base {...}
optional<Base> x = Derived();
y->call_virtual_functions()
Current design of boost::optional doesn'g support this. But I wonder if it's
to possible to extend it.
I created simple prototype to verify the technique (see attachment). It
works this way:
optional<BaseT>
- has attribut _value_holder of type value_holder<BaseT>*
- _value_holder points to the instance of derived_value_holder<BaseT,
DerivedT>, where DerivedT is the type of stored value
value_holder<BaseT>
- abstract class
- can be cloned (deep copy)
derived_value_holder<BaseT, DerivedT>
- is derived from value_holder<BaseT>
- contains DerivedT value (cloned with copy constructor)
What do you think about it?
Regards,
Vaclav
begin 666 optional_test.cpp
M(VEN8VQU9&4@/&EO<W1R96%M/@T*#0IU<VEN9R!N86UE<W!A8V4@<W1D.PT*
M#0HO+RTM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#0H-"F-L87-S
M($$-"GL-"G!U8FQI8SH-"B @("!V:7)T=6%L('9O:60@=&5S="@I(&-O;G-T
M#0H@(" @>PT*(" @(" @("!C;W5T(#P\(")!(B \/"!E;F1L.PT*(" @('T-
M"GT[#0H-"F-L87-S($(Z#0H@(" @<'5B;&EC($$-"GL-"G!U8FQI8SH-"B @
M("!V:7)T=6%L('9O:60@=&5S="@I(&-O;G-T#0H@(" @>PT*(" @(" @("!C
M;W5T(#P\(")"(B \/"!E;F1L.PT*(" @('T-"GT[#0H-"B\O+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2T-"B\O(%9A;'5E(&AO;&1E<B!B87-E
M(&9O<B!V86QU97,@9&5R:79E9"!F<F]M($)A<V54#0H-"G1E;7!L871E/'1Y
M<&5N86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\O($]P=&EO;F%L
M(&AO;&1S('9A;'5E7VAO;&1E<CQ"87-E5#X@<&]I;G1E<B!T;PT*+R\@:6YS
M=&%N8V4@;V8_at_9&5R:79E9%]V86QU95]H;VQD97(\0F%S950L(#\_/SX-"@T*
M=&5M<&QA=&4\='EP96YA;64_at_0F%S950^#0IC;&%S<R!O<'1I;VYA; T*>PT*
M<'5B;&EC._at_T*#0H@(" @;W!T:6]N86PH*0T*(" @(#H@("!?=F%L=65?:&]L
M9&5R*$Y53$PI#0H@(" @>PT*(" @('T-"@T*(" @(&]P=&EO;F%L*&-O;G-T
M(&]P=&EO;F%L)B!O=&AE<BD-"B @(" Z(" @7W9A;'5E7VAO;&1E<BAO=&AE
M<BY?=F%L=65?:&]L9&5R+3YC;&]N92_at_I*0T*(" @('L-"B @("!]#0H-"B @
M("!T96UP;&%T93QT>7!E;F%M92!$97)I=F5D5#X-"B @("!O<'1I;VYA;"AC
M;VYS="!$97)I=F5D5"8@=F%L=64I#0H@(" @.B @(%]V86QU95]H;VQD97(H
M;F5W(&1E<FEV961?=F%L=65?:&]L9&5R/$)A<V54+"!$97)I=F5D5#XH=F%L
M=64I*0T*(" @('L-"B @("!]#0H-"B @("!^;W!T:6]N86PH*0T*(" @('L-
M"B @(" @(" @9&5L971E(%]V86QU95]H;VQD97([#0H@(" @?0T*#0H@(" @
M0F%S950J(&]P97)A=&]R+3XH*2!C;VYS= T*(" @('L-"B @(" @(" @<F5T
M=7)N(%]V86QU95]H;VQD97(M/F=E="@I.PT*(" @('T-"@T*(" @('9A;'5E
M7VAO;&1E<CQ"87-E5#XJ(%]V86QU95]H;VQD97([#0I].PT*#0HO+RTM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#0H-"G9O:60@;6%I;B_at_I#0I[
M#0H@(" @+R\@0W)E871E(&YE=R!O<'1I;VYA;"!V86QU90T*(" @(&]P=&EO
M;F%L/$$^('@@/2!"*"D[#0H@(" @>"T^=&5S="@I.PT*#0H@(" @+R\@0V]P
M>2!O<'1I;VYA;"!V86QU90T*(" @(&]P=&EO;F%L/$$^('DH>"D[#0H@(" @
M>2T^=&5S="@I.PT*?0T*#0HO+RTM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
(+2TM+2TM#0H`
`
end
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk