Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Struct template when

boost::proto::when — A grammar element and a PrimitiveTransform that associates a transform with the grammar.

Synopsis

// In header: <boost/proto/transform/when.hpp>

template<typename Grammar, typename PrimitiveTransform> 
struct when :  PrimitiveTransform {
  // types
  typedef  ;
};

Description

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>().
proto::or_<
    proto::terminal<proto::_>, proto::_state>()>,
    proto::fold<proto::_, proto::_state, 

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).


PrevUpHomeNext