| Home | Libraries | People | FAQ | More

## Struct _

boost::proto::_ — A wildcard grammar element that matches any expression, and a transform that returns the current expression unchanged.

## Synopsis

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

    struct _ :  proto::transform<_> {
      // types
      typedef _ proto_grammar;

      // member classes/structs/unions
      template<typename Expr, typename State, typename Data>
      struct impl :  proto::transform_impl<Expr, State, Data> {
        // types
        typedef Expr result_type;

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

## Description

The wildcard type, `proto::_`, is a grammar element such that `proto::matches<E, proto::_>::value` is `true` for any expression type `E`.

The wildcard can also be used as a stand-in for a template argument when matching terminals. For instance, the following is a grammar that will match any `std::complex<>` terminal:

    BOOST_MPL_ASSERT((
      proto::matches<
        proto::terminal<std::complex<double> >::type,
        proto::terminal<std::complex< proto::_ > >
      >
    ));

When used as a transform, `proto::_` returns the current expression unchanged. For instance, in the following, `proto::_` is used with the `proto::fold<>` transform to fold the children of a node:

    struct CountChildren :
      proto::or_<
        // Terminals have no children
        proto::when<proto::terminal<proto::_>, mpl::int_<0>()>,
        // Use proto::fold<> to count the children of non-terminals
        proto::otherwise<
          proto::fold<
            proto::_, // <-- fold the current expression
            mpl::int_<0>(),
            mpl::plus<proto::_state, mpl::int_<1> >()
          >
        >
      >
    {};