3 Aug
2009
3 Aug
'09
1:50 p.m.
My restriction is that f takes a ABC const-ref as an input. Can I construct the variant from the const ABC& abc Maybe like variant
v(abc); without deep copying. The Di objects are big.
Then I would apply the visitation.
Maybe storing variant
...
Yes, you can store ptrs in the variant.
So f would look like
void f( const ABC& abc ) { const VariantTypeDefProvidedByLib v(&abc);
v.apply_visitor( YourVisitor ); }
You cannot construct the variant in f(), because you already lost the compile-time type of the object - it's ABC now. If you'd like to work with ABC's and virtual functions, then why do you need variant? Variant is about preserving the compile-time type.