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

Click here to view the latest version of this page.

Struct template switch_

boost::proto::switch_ — For matching one of a set of alternate grammars, which are looked up based on an expression's tag type. When used as a transform, proto::switch_<> applies the transform associated with the sub-grammar that matches the expression.


// In header: <boost/proto/matches.hpp>

template<typename Cases> 
struct switch_ :  proto::transform<switch_<Cases> > {
  // types
  typedef switch_ proto_grammar;

  // member classes/structs/unions
  template<typename Expr, typename State, typename Data> 
  struct impl :  
    Cases::template case_<typename Expr::tag_type>::template impl<Expr, State, Data>


An expression type E matches proto::switch_<C> if E matches C::case_<E::proto_tag>.

When applying proto::switch_<C> as a transform with an expression e of type E, state s and data d, it is equivalent to C::case_<E::proto_tag>()(e, s, d).