]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/metaparse/doc/first_of.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / metaparse / doc / first_of.qbk
CommitLineData
7c673cae
FG
1[#first_of]
2[section first_of]
3
4[h1 Synopsis]
5
6 template <class P1, /* ... */, class Pn>
7 struct first_of;
8
9This is a [link parser_combinator parser combinator].
10
11[table Arguments
12 [[Name] [Type]]
13 [[`P1` .. `Pn`] [[link parser parser]]]
14]
15
16[h1 Description]
17
18`first_of` applies the `P1` ... `Pn` parsers in sequence. It accepts an input
19when all parsers accept it. The result of parsing is the result of the first
20parser.
21
22[h1 Header]
23
24 #include <boost/metaparse/first_of.hpp>
25
26[h1 Expression semantics]
27
28For any `p1`, ... `pn` parsers
29
30 first_of<p1, ..., pn>
31
32is equivalent to
33
34 nth_of_c<0, p1, ..., pn>
35
36[h1 Example]
37
38 #include <boost/metaparse/first_of.hpp>
39 #include <boost/metaparse/int_.hpp>
40 #include <boost/metaparse/lit_c.hpp>
41 #include <boost/metaparse/string.hpp>
42 #include <boost/metaparse/start.hpp>
43 #include <boost/metaparse/is_error.hpp>
44 #include <boost/metaparse/get_result.hpp>
45
46 #include <type_traits>
47
48 using namespace boost::metaparse;
49
50 using int_with_semicolon = first_of<int_, lit_c<';'>>;
51
52 static_assert(
53 is_error<
54 int_with_semicolon::apply<BOOST_METAPARSE_STRING("13"), start>
55 >::type::value,
56 "int without semicolon is rejected"
57 );
58
59 static_assert(
60 get_result<
61 int_with_semicolon::apply<BOOST_METAPARSE_STRING("13;"), start>
62 >::type::value,
63 "the result is the result of the first parser"
64 );
65
66[endsect]
67