• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[#last_of]
2[section last_of]
3
4[h1 Synopsis]
5
6  template <class... Ps>
7  struct last_of;
8
9This is a [link parser_combinator parser combinator].
10
11[table Arguments
12  [[Name]       [Type]]
13  [[`Ps...`]    [[link parser parser]s]]
14]
15
16[h1 Description]
17
18`last_of` applies the `Ps...` parsers in sequence. It accepts an input when all
19parsers accept it. The result of parsing is the result of the last parser.
20
21On compilers, which are not C++11-compliant, the maximum number of parsers
22`last_of` accepts can be specified with the
23`BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE` macro. Its default value is `5`.
24
25[h1 Header]
26
27  #include <boost/metaparse/last_of.hpp>
28
29[h1 Expression semantics]
30
31For any `p1`, ... `pn` parsers
32
33  first_of<p1, ..., pn>
34
35is equivalent to
36
37  nth_of_c<n, p1, ..., pn>
38
39[h1 Example]
40
41  #include <boost/metaparse/last_of.hpp>
42  #include <boost/metaparse/int_.hpp>
43  #include <boost/metaparse/lit_c.hpp>
44  #include <boost/metaparse/string.hpp>
45  #include <boost/metaparse/start.hpp>
46  #include <boost/metaparse/is_error.hpp>
47  #include <boost/metaparse/get_result.hpp>
48
49  #include <type_traits>
50
51  using namespace boost::metaparse;
52
53  using comma_int = last_of<lit_c<','>, int_>;
54
55  static_assert(
56    is_error<comma_int::apply<BOOST_METAPARSE_STRING("13"), start>>::type::value,
57    "int without comma is rejected"
58  );
59
60  static_assert(
61    get_result<
62      comma_int::apply<BOOST_METAPARSE_STRING(",13"), start>
63    >::type::value,
64    "the result is the result of the last parser"
65  );
66
67[endsect]
68
69