Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

one_of_c

Synopsis

template <long P1, long P2, /* ... */ long Pn>
struct one_of_c;

This is a parser.

Table 66. Arguments

Name

Type

P1 .. Pn

character values


Description

It accepts inputs beginning with any of the P1, ..., Pn characters. The result of parsing is the first character of the input.

The maximum number of characters that can be provided is defined by the BOOST_METAPARSE_LIMIT_ONE_OF_SIZE macro. Its default value is 20.

Header

#include <boost/metaparse/one_of_c.hpp>

Expression semantics

For any c1, ..., cn characters

one_of_c<c1, ..., cn>

is equivalent to

one_of<lit_c<c1>, /* ... */, lit_c<cn>>

Example

#include <boost/metaparse/one_of_c.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/get_result.hpp>
#include <boost/metaparse/is_error.hpp>

using namespace boost::metaparse;

using whitespace = one_of_c<' ', '\n', '\r', '\t', '\v'>;

static_assert(
  get_result<
    whitespace::apply<BOOST_METAPARSE_STRING(" "), start>
  >::type::value == ' ',
  "the result of parsing should be the first character of the input"
);

static_assert(
  is_error<whitespace::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  "it should return an error when the input does not begin with a whitespace"
);

PrevUpHomeNext