There is no direct way, but you can make static_visitor pretty short with templates.
Changed from promotion docs:
struct boo_generic : public boost::static_visitor<> { template <typename T> void operator()( T & operand ) const { operand.boo(); } };
Now you can do this:
boost::apply_visitor( boo_generic(), v );
Infact you can generalize this to take a pointer to a function of your base class:
struct fn_generic : public boost::static_visitor<> { fn_generic( void (IBase::fn)() ) : fn_(fn) {} template<T> void operator() ( T & op ) const { op.*fn(); } }
Then you can do:
boost::apply_visitor( boo_generic( IBase::boo ), v );
Or something like that - I probably misunderstood the syntax of a function pointer, but I hope you understand this idea.
source share