Boost C++ Libraries Home Libraries People FAQ More

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< Data >::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