Boost logo

Boost Users :

Subject: [Boost-users] Template type questions
From: Glenn Macgregor (gmacgregor_at_[hidden])
Date: 2009-12-17 11:39:57

Hi All,

I am using the boost::variant with the binary visitor algorithm, apply_visitor.

struct UnknownValue {};
typedef boost::variant<UnknownValue, long, unsigned long, double, string, char> ValueType;

I am using apply_visitor for binary visitation as below:

class AddVisitor : public boost::static_visitor<> {
                template <typename T>
                void operator()(const T &lhs, const T &rhs) {
                                T val = lhs + rhs;

                template <typename T, typename R>
                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?



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at