I'm trying to create a lookup table for ints to a boost::static_visitor
using VariableValue = boost::variant<int, double, std::string>;
struct low_priority {};
struct high_priority : low_priority {};
struct Mul : boost::static_visitor < VariableValue>{
template <typename T, typename U>
auto operator() (high_priority, T a, U b) const -> decltype(VariableValue(a * b)) {
return a * b;
}
template <typename T, typename U>
VariableValue operator() (low_priority, T, U) const {
throw std::runtime_error("Incompatible arguments");
}
template <typename T, typename U>
VariableValue operator() (T a, U b) const {
return (*this)(high_priority{}, a, b);
}
};
const std::map < int, boost::static_visitor<VariableValue> > binopHelper = {
{1, Mul{}}
};
However when I do the following:
std::cout << (VariableValue)boost::apply_visitor(binopHelper.at(1), (VariableValue)2, (VariableValue)4) << std::endl;
I get the error:
term does not evaluate to a function taking 2 arguments (compiling source file interpreter.cpp)
How can I make it so that static_visitor takes 2 arguments to match that of Mul
?