3 Aug
2009
3 Aug
'09
12:56 p.m.
typedef boost::variant
ABCDerived; and the user could write visitors to visit ABCDerived objects, here the user is enforced to implement all cases in the visitor.
but then the function f expects ABC objects. Can I still do:
void f( const ABC& abc ) { // how to write code to use the visitors with abc ? }
struct YourVisitor : boost::static_visitor<functor return type> { result_type operator()(const D1 &d1) {...} result_type operator()(const D2 &d1) {...} // etc. for all the type in the variant }; then: boost::apply_visitor(YourVisitor(), yourVariant);