#include #include #include #include namespace proto=boost::proto; namespace mpl=boost::mpl; using proto::_; namespace pretty { struct i_tag{}; typedef boost::mpl::int_<0> zero; typedef boost::mpl::int_<1> one; struct multiplies_complex : std::multiplies< std::complex >, proto::callable{}; struct plus_complex : std::plus< std::complex >, proto::callable{}; struct complex_cartesian_grammar : proto::or_< proto::when< proto::terminal, std::complex(proto::_value, zero()) >, proto::when< proto::terminal, std::complex(zero(), one()) >, proto::when< proto::multiplies< complex_cartesian_grammar, complex_cartesian_grammar >, multiplies_complex( complex_cartesian_grammar(proto::_left), complex_cartesian_grammar(proto::_right) ) >, proto::when< proto::plus< complex_cartesian_grammar, complex_cartesian_grammar >, plus_complex( complex_cartesian_grammar(proto::_left), complex_cartesian_grammar(proto::_right) ) > >{}; template< typename Expr > struct complex_cartesian_expr; struct complex_cartesian_domain : proto::domain< proto::pod_generator< complex_cartesian_expr >, complex_cartesian_grammar >{}; template struct complex_cartesian_expr { BOOST_PROTO_EXTENDS( Expr, complex_cartesian_expr, complex_cartesian_domain ) template operator std::complex() const { return complex_cartesian_grammar()(*this); } }; complex_cartesian_expr::type> const i = {}; } int main(){ using namespace pretty; std::complex z = 4. + 5.*i; return 0; }