]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/doc/if_.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / metaparse / doc / if_.qbk
1 [#if_]
2 [section if_]
3
4 [h1 Synopsis]
5
6 template <class P, class T, class F>
7 struct if_;
8
9 This is a [link parser_combinator parser combinator].
10
11 [table Arguments
12 [[Name] [Type]]
13 [[`P`] [[link parser parser]]]
14 [[`T`] [[link metaprogramming_value template metaprogramming value]]]
15 [[`F`] [[link metaprogramming_value template metaprogramming value]]]
16 ]
17
18 [h1 Description]
19
20 `if_` always accepts the input string. The result of parsing is `T`, when `P`
21 accepts the input and `F` otherwise.
22
23 [h1 Header]
24
25 #include <boost/metaparse/if_.hpp>
26
27 [h1 Expression semantics]
28
29 For any `p` parser, `t` and `f` classes the following are equivalent:
30
31 if_<p, t, f>
32
33 one_of<last_of<p, return_<t>>, return_<f>>
34
35 [h1 Example]
36
37 #include <boost/metaparse/if_.hpp>
38 #include <boost/metaparse/int_.hpp>
39 #include <boost/metaparse/string.hpp>
40 #include <boost/metaparse/start.hpp>
41 #include <boost/metaparse/get_result.hpp>
42
43 #include <type_traits>
44
45 using namespace boost::metaparse;
46
47 using int11 = std::integral_constant<int, 11>;
48 using int13 = std::integral_constant<int, 13>;
49
50 static_assert(
51 get_result<
52 if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("1234"), start>
53 >::type::value == 11,
54 "When the int_ parser succeeds, the result of parsing should be 11"
55 );
56
57 static_assert(
58 get_result<
59 if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("foo"), start>
60 >::type::value == 13,
61 "When the int_ parser fails, the result of parsing should be 13"
62 );
63
64 [endsect]
65