boost c++ setWert von boost::variant< ..

jkallup

Erfahrenes Mitglied
#1
Hallo,

wie kann ich mittels boost einen get auch ein set wert zuweisen?
also nicht nur get: wert = boost::get<int>(expr);
sondern setWert(12);

???
Danke
jkallup

Code:
struct expression_ast
    {
        typedef
            boost::variant<
                  nil
                , int
                , double
                , dBaseTypes
                , std::string
                , boost::recursive_wrapper<expression_ast>
                , boost::recursive_wrapper<binary_op>
                , boost::recursive_wrapper<unary_op>
                , boost::recursive_wrapper<class_op>
                , boost::recursive_wrapper<dBaseExpression>
            >
        type;
        type expr;
...
};




expression_ast lexp = left;
if (boost::get<int>(lexp.expr) < boost::get<int>(right.expr))
lexp.expr = value_int;
left = lexp;








    struct binary_op
    {
        binary_op(
              char op
            , expression_ast const& left
            , expression_ast const& right)
            : op(op)
            , left(left)
            , right(right)
        {
            int lval,rval, value_int;


            cout << "11111111111111111\n";


            try {
                lval = boost::get<double>(left.expr);
            }   catch (...) {
                try {
                    lval = boost::get<int>   (left.expr);
                }   catch (...) {
                }
            }


            cout << "122222222222222222222222222222222\n";


            try {
                rval = boost::get<double>(right.expr);
            }   catch (...) {
                rval = boost::get<int>   (right.expr);
            }


            cout << "AAAAAAAAAAAAAAAAAAAAAAA\n";


            if (op == '+') value_int = lval + rval; else
            if (op == '-') value_int = lval - rval; else
            if (op == '*') value_int = lval * rval; else
            if (op == '/') value_int = lval / rval;


            cout << "ER: " << value_int << endl;
            try {
                expression_ast lexp = left;
                if (boost::get<int>(lexp.expr) < boost::get<int>(right.expr))
                lexp.expr = value_int;
                left = lexp;
                cout << "SSSSSSSSSSSSSS\n";
            }   catch (...) {
                try {
                    expression_ast lexp = left;
                    if (boost::get<double>(lexp.expr) < boost::get<double>(right.expr))
                    lexp.expr = double(value_int);
                }   catch (...) {


                }
            }


            cout << "DDDDDDDDDDDDDD\n";
            /*
            if (flag == 1)  {
                if (value_int > boost::get<double>(right.expr))
                right.expr = value_int;
            }   else {
                if (value_int > boost::get<int>(right.expr))
                right.expr = value_int;
            }
*/
            std::cout << "Math2: " << value_int << std::endl;
        }


        char op;
        expression_ast left;
        expression_ast right;
    };