Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

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

boost::proto::when<Grammar, R(A..., ...)> — A grammar element and a Transform 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_grammar proto_grammar;

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

Note: In the specialization when<G, R(A..., ...)>, the first ellipsis denotes a C++11-style variadic template (which is emulated for C++98 compilers). The second ellipsis is a C-style vararg.


PrevUpHomeNext