The visitor pattern reification will make the compiler do the type-checking for you. All you need to do is tell the compiler what to do when a string
is in the Variant
:
(check out the example at http://www.boost.org/doc/libs/1_35_0/doc/html/variant/tutorial.html)
struct my_dispatcher : public boost::static_visitor<> {
test* t;
my_dispatcher(test* t): t(t) {}
void operator()( string s ) { t.func3(s); }
void operator()( double d ) { t.func4(d); }
//... for each supported type
};
and use boost::apply_visitor
to choose the correct function:
int main ()
{
test t;
my_dispatcher dispatcher(&t);
Variant V = 3;
boost::apply_visitor( dispatcher, v );
V = "hello";
boost::apply_visitor( dispatcher, v );
}
The my_dispatcher(&t)
will create an object of your static_visitor implementation, that will be used by the apply_visitor
magic.
Hope that's what your were looking fore, since your question wasn't really clear.
Note: alternatively, you derive your test
from static_visitor
.