Можно ли сохранить возвращаемое значение boost :: apply_visitor в переменной-члене?

Можно ли сохранить возвращаемое значение boost::apply_visitor в переменной-члене класса?
мне нужно получить Test::Do работать, но не знаю как.

#include "boost/variant/variant.hpp"#include "boost/variant/apply_visitor.hpp"
using namespace std;
using namespace boost;

class times_two_generic
: public boost::static_visitor<>
{
public:

template <typename T>
void operator()( T & operand ) const
{
operand += operand;
}

};

class Test
{
public:
Test(){
times_two_generic visitor;
//mAppliedVisitor = apply_visitor(visitor);
}
~Test(){}
void Do(variant<int, string> &v)
{
//mAppliedVisitor(v);   // Is it possible to store the value of apply_visitor
// in mAppliedVisitor only once in the constructor of Test?
// and only call mAppliedVisitor member whenever needed.
}

private:
// boost::apply_visitor_delayed_t<times_two_generic> mAppliedVisitor;
};

int main(int argc, char **argv)
{
variant<int, string> v = 5;
times_two_generic visitor;

cout << v << endl;

apply_visitor(visitor)(v); // v => 10
boost::apply_visitor_delayed_t<times_two_generic> appliedVisitor = apply_visitor(visitor);
appliedVisitor(v); // v => 20

Test t;
t.Do(v);

cout << v << endl;
return 0;
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector