typedef boost::variant<int, double> Type;
class Append: public boost::static_visitor<>
{
public:
void operator()(int)
{}
void operator()(double)
{}
};
Type type(1.2);
Visitor visitor;
boost::apply_visitor(visitor, type);
Is it possible to change the visitor such that it receives extra data as follows:
class Append: public boost::static_visitor<>
{
public:
void operator()(int, const std::string&)
{}
void operator()(double, const std::string&)
{}
};
This string value changes during the lifetime of the Append object. Passing the string in via the constructor is not an option in this case.
The “additional argument” that gets given to each call is the
thispointer. Use it to pass whatever additional information that you need: