• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#one_of_c]
2[section one_of_c]
3
4[h1 Synopsis]
5
6  template <char... Cs>
7  struct one_of_c;
8
9This is a [link parser parser].
10
11[table Arguments
12  [[Name] [Type]]
13  [[`Cs`] [character values]]
14]
15
16[h1 Description]
17
18It accepts inputs beginning with any of the `Cs...` characters. The result of
19parsing is the first character of the input.
20
21On compilers, which are not C++11-compliant, the maximum number of characters
22that can be provided is defined by the `BOOST_METAPARSE_LIMIT_ONE_OF_SIZE`
23macro. Its default value is `20`.
24
25[h1 Header]
26
27  #include <boost/metaparse/one_of_c.hpp>
28
29[h1 Expression semantics]
30
31For any `c1`, ..., `cn` characters
32
33  one_of_c<c1, ..., cn>
34
35is equivalent to
36
37  one_of<lit_c<c1>, /* ... */, lit_c<cn>>
38
39[h1 Example]
40
41  #include <boost/metaparse/one_of_c.hpp>
42  #include <boost/metaparse/start.hpp>
43  #include <boost/metaparse/string.hpp>
44  #include <boost/metaparse/get_result.hpp>
45  #include <boost/metaparse/is_error.hpp>
46
47  using namespace boost::metaparse;
48
49  using whitespace = one_of_c<' ', '\n', '\r', '\t', '\v'>;
50
51  static_assert(
52    get_result<
53      whitespace::apply<BOOST_METAPARSE_STRING(" "), start>
54    >::type::value == ' ',
55    "the result of parsing should be the first character of the input"
56  );
57
58  static_assert(
59    is_error<whitespace::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
60    "it should return an error when the input does not begin with a whitespace"
61  );
62
63[endsect]
64
65