Hallo,
wie kann man vernestetete variants runtersplitten?
in der operator + member, mekkert der g++ compiler.
wäre für sachdienliche hinweise und problem lösern dankbar
Gruß
jens
wie kann man vernestetete variants runtersplitten?
in der operator + member, mekkert der g++ compiler.
wäre für sachdienliche hinweise und problem lösern dankbar
Code:
struct add_ { };
struct sub_ { };
struct mul_ { };
struct div_ { };
struct expr { };
struct sconst { };
struct mconst { };
template <typename OpTag1> struct binary_op;
template <typename OpTag2> struct cmd_print;
template <typename OpTag3> struct cmd_varset;
template <typename OpTag> struct TypeDouble;
template <typename OpTag> struct TypeDoublePrint;
typedef boost::variant<
double
, std::string
, boost::recursive_wrapper< binary_op<add_> >
, boost::recursive_wrapper< binary_op<sub_> >
, boost::recursive_wrapper< binary_op<mul_> >
, boost::recursive_wrapper< binary_op<div_> >
, boost::recursive_wrapper< cmd_varset<TypeDouble <int> > >
, boost::recursive_wrapper< cmd_print <TypeDoublePrint<int> > >
> expression;
expression& operator + (expression& exp1, expression& exp2) {
std::cout << "plus" << std::endl;
std::cout << "------" << std::endl;
std::cout << typeid(exp1).name() << std::endl;
std::cout << typeid(exp2).name() << std::endl;
std::cout << "======" << std::endl;
expression tmp1 = boost::get<expression>(exp1);
expression tmp2 = boost::get<expression>(exp2);
cmd_varset<TypeDouble<int> > td1 = boost::get<cmd_varset<TypeDouble<int> > >(tmp1);
cmd_varset<TypeDouble<int> > td2 = boost::get<cmd_varset<TypeDouble<int> > >(tmp2);
TypeDouble<int> td3 = boost::get<TypeDouble<int> >(td1);
TypeDouble<int> td4 = boost::get<TypeDouble<int> >(td2);
double d1 = boost::get<double>(td3);
double d2 = boost::get<double>(td4);
double res = d1 + d2;
expression tmp = res;
return tmp;
}
Gruß
jens