| Home | Libraries | People | FAQ | More

## Struct template when

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

## Synopsis

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

## 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>().
    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:

`proto::when<G,T>::impl<E,S,V>::type` is the same as `T::impl<E,S,V>::type`.

`proto::when<G,T>()(e,s,v)` is the same as `T()(e,s,v)`.