lundi 13 avril 2015

Boost variant visitor with an extra parameter

I have code that resembles below.



typedef uint32_t IntType;
typedef IntType IntValue;
typedef boost::variant<IntValue, std::string> MsgValue;

MsgValue v;


Instead of sayng this,



IntValue value = boost::apply_visitor(d_string_int_visitor(), v);


I would like to pass an extra parameter like this: But operator() gives a compile error.



IntValue value = boost::apply_visitor(d_string_int_visitor(), v, anotherStr);

class d_string_int_visitor : public boost::static_visitor<IntType>
{
public:
inline IntType operator()(IntType i) const
{
return i;
}

inline IntValue operator()(const std::string& str) const noexcept
{
// code in here
}

//I want this, but
inline IntValue operator()(const std::string& str, const std::string s) const noexcept
{
// code in here
}
};

Aucun commentaire:

Enregistrer un commentaire