AMDG Glenn Macgregor wrote:
Hi All,
I am using the boost::variant with the binary visitor algorithm, apply_visitor.
struct UnknownValue {}; typedef boost::variant
ValueType; I am using apply_visitor for binary visitation as below:
class AddVisitor : public boost::static_visitor<> { public: template <typename T> void operator()(const T &lhs, const T &rhs) { T val = lhs + rhs; }
template
void operator()(const T &lhs, const R &rhs) { // do nothing...different types } template <typename T> void operator()(const T &lhs, const UnknownValue &rhs) { // do nothing...we have an unknown value }
template <typename T> void operator()(const UnknownValue &lhs, const T &rhs) { // do nothing...we have an unknown value }
void operator()(const UnknownValue &lhs, const UnknownValue &rhs) { // do nothing...we have an unknown value } };
The above is not complete because I can do addition if the types are long and unsigned long or long and double or long and char...etc.
What is the preferred method for doing this? Do I need to create an overridden operator() for every argument combination that is valid or can I get the argument types in the function?
You can try using enable_if/disable_if with is_arithmetic. In Christ, Steven Watanabe