Home | Libraries | People | FAQ | More |
boost::proto::when — A grammar element and a PrimitiveTransform that associates a transform with the grammar.
// In header: <boost/proto/transform/when.hpp> template<typename Grammar, typename PrimitiveTransform = Grammar> struct when : PrimitiveTransform { // types typedef typename Grammar::proto_grammar proto_grammar; };
Use proto::when<>
to override a grammar's default
transform with a custom transform. It is for used when composing larger transforms by
associating smaller transforms with individual rules in your grammar, as in the following
transform which counts the number of terminals in an expression.
// Count the terminals in an expression tree. // Must be invoked with initial state == mpl::int_<0>(). struct CountLeaves : proto::or_< proto::when<proto::terminal<proto::_>, mpl::next<proto::_state>()>, proto::otherwise<proto::fold<proto::_, proto::_state, CountLeaves> > > {};
In proto::when<G, T>
, when T
is a class type it is a PrimitiveTransform and the following equivalencies hold:
boost::result_of<proto::when<G,T>(E,S,V)>::type
is the same as
boost::result_of<T(E,S,V)>::type
.
proto::when<G,T>()(e,s,d)
is the same as
T()(e,s,d)
.