Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2005-03-16 15:51:41


Hi everybody,

I am rather curious about how static visitation on boost::variant works and
I was wondering if someone can enlighten me about this. For example,
consider the following:

boost::variant<long, std::string> vFoo;
class my_visitor : public boost::static_visitor<>
{
        operator()(long nValue) { ... }
        operator()(std::string strValue) { ... }
};

vFoo = 1; //"current" type is long
boost::apply_visitor(my_visitor(), vFoo); //call operator()(long nValue)
vFoo = "me"; //"current" type is std::string
boost::apply_visitor(my_visitor(), vFoo); //call operator()(std::string
strValue)

What I do not understand is, the "current" variant type seems to be changed
at runtime (at assignment), then how can apply_vistor know which operator()
to call at compile time?

Thanks

-delfin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net