//Purpose: // Attempt to generalize pass_through to allow transform on operator, // i.e. the tag, as well as arguments in an expression. // #include #include #include #include #include namespace boost { namespace proto { namespace transform { /// \brief A PrimitiveTransform that returns the current expression /// tag. template < templateclass TagMap=mpl::identity > struct expr_tag: proto::callable { template < typename Sig > struct result; template < typename This , typename Tag , typename Args , long Arity , typename State , typename Visitor > struct result < This ( proto::expr , State , Visitor ) > { typedef typename TagMap::type type; }; /// \param expr_ The current expression. /// \return \c expr_ /// \throw nothrow template < typename Tag , typename Args , long Arity , typename State , typename Visitor > typename TagMap::type operator () ( proto::expr const & , State const & , Visitor & ) const { typedef typename TagMap::type target_tag; return target_tag(); } }; }//exit transform namespace template < templateclass TagMap > struct is_callable < transform::expr_tag > : mpl::true_ {}; using transform::expr_tag; namespace exprns_ { template < class Arg0 > struct expr < tag::dereference , args0 , 0 > { expr(expr,0>const&) {} }; template < class Arg0To > struct expr < tag::posit , args1 , 1 > { template < class Arg0From > expr(expr,1>const&) {} }; }//exit exprns_ namespace }//exit proto namespace }//exit boost namespace using namespace boost; struct morph_ident : proto::when < proto::nary_expr < proto::_ , proto::vararg > #if 1 , proto::nary_expr < proto::expr_tag<> , proto::vararg > #endif > {}; template < class Tag > struct tag_map ; template < > struct tag_map < proto::tag::terminal > { typedef proto::tag::dereference type; }; template < > struct tag_map < proto::tag::negate > { typedef proto::tag::posit type; }; struct morph_map : proto::when < proto::nary_expr < proto::_ , proto::vararg > #if 1 , proto::nary_expr < proto::expr_tag , proto::vararg > #endif > {}; int main(void) { using namespace boost::proto; int state,visitor; typedef terminal leaf_int_gram; typedef leaf_int_gram::type leaf_int_expr; leaf_int_expr leaf_int_valu; morph_ident morph_ident_valu; leaf_int_expr leaf_int_xfrm=morph_ident_valu(leaf_int_valu,state,visitor); typedef negate negate_int_gram; typedef negate::type negate_int_expr; negate_int_expr negate_int_valu; negate_int_expr negate_int_xfrm=morph_ident_valu(negate_int_valu,state,visitor); typedef negate negate2_int_gram; typedef negate::type negate2_int_expr; negate2_int_expr negate2_int_valu; negate2_int_expr negate2_int_xfrm=morph_ident_valu(negate2_int_valu,state,visitor); morph_map morph_map_valu; typedef expr > leaf_int_map_expr; leaf_int_map_expr leaf_int_map_valu=morph_map_valu(leaf_int_valu,state,visitor); typedef expr > negate_int_map_expr; negate_int_map_expr negate_int_map_valu=morph_map_valu(negate_int_valu,state,visitor); return 0; }