| Home | Libraries | People | FAQ | More

## Struct template when<Grammar, R(A...)>

boost::proto::when<Grammar, R(A...)> — 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 R, typename... A>
    struct when<Grammar, R(A...)> :  proto::transform< when<Grammar, R(A...)> > {
      // types
      typedef typename Grammar::proto_base_expr proto_base_expr;

      // member classes/structs/unions
      template<typename Expr, typename State, typename Data>
      struct impl :  proto::transform_impl< Expr, State, Data > {
        // types
        typedef proto::call<R(A...)>                                       call_;        // For exposition only
        typedef proto::make<R(A...)>                                       make_;        // For exposition only
        typedef typename mpl::if_<proto::is_callable<R>,call_,make_>::type which;        // For exposition only
        typedef typename boost::result_of<which(Expr, State, Data)>::type  result_type;

        // public member functions
        result_type operator()(typename impl::expr_param,
                               typename impl::state_param,
                               typename impl::data_param) const;
      };
    };

## Description

Use `proto::when<>` to override a grammar's default transform with a custom transform. It is for use when composing larger transforms by associating smaller transforms with individual rules in your grammar.

The `when<G, R(A...)>` form accepts either a CallableTransform or an ObjectTransform as its second parameter. `proto::when<>` uses `proto::is_callable<R>::value` to distinguish between the two, and uses `proto::call<>` to evaluate CallableTransforms and `proto::make<>` to evaluate ObjectTransforms.