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, proto::external_transform>

boost::proto::when<Grammar, > — A grammar element that associates an externally-specified transform with the grammar. The transform is looked up in the Data parameter using the Grammar as a key.

Synopsis

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

template<typename Grammar> 
struct when<Grammar, proto::external_transform> :
   
  proto::transform< when<Grammar, proto::external_transform> >
{
  // types
  typedef typename Grammar::proto_grammar proto_grammar;

  // member classes/structs/unions
  template<typename Expr, typename State, typename Data> 
  struct impl :  
    boost::remove_reference< 
      typename mpl::eval_if_c<
        proto::result_of::has_env_var<Data, proto::transforms_type>::value,
        proto::result_of::env_var<Data, proto::transforms_type>,
        proto::result_of::env_var<Data, proto::data_type>
      >::type
    >::type
      ::template when< Grammar >
        ::template impl< Expr, State, Data >
  {
  };
};

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, proto::external_transform> indicates that the associated transform is not yet known. It should be looked up when the transform is about to be applied. It is found by looking it up in the passed-in Data parameter, which behaves like a compile-time map from grammar types to transform types. The map is indexed using Grammar as a key. The associated value type is used as the transform to apply. In this way, the same grammar can be used to define multiple evaluating strategies that can be added post-hoc.

See proto::external_transforms for an example.


PrevUpHomeNext