]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/metaparse/doc/always.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / metaparse / doc / always.qbk
1 [#always]
2 [section always]
3
4 [h1 Synopsis]
5
6 template <class P, class T>
7 struct always;
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 ]
16
17 [h1 Description]
18
19 It accepts an input if and only if `P` accepts it, but the result of parsing
20 will be `T` instead of the result `P` returned.
21
22 [h1 Header]
23
24 #include <boost/metaparse/always.hpp>
25
26 [h1 Expression semantics]
27
28 For any `p` parser and `t` class the following are equivalent:
29
30 always<p, t>
31
32 last_of<p, return_<t>>
33
34 [h1 Example]
35
36 #include <boost/metaparse/always.hpp>
37 #include <boost/metaparse/lit_c.hpp>
38 #include <boost/metaparse/start.hpp>
39 #include <boost/metaparse/string.hpp>
40 #include <boost/metaparse/is_error.hpp>
41 #include <boost/metaparse/get_result.hpp>
42
43 #include <type_traits>
44
45 using namespace boost::metaparse;
46
47 using always13 = always<lit_c<'x'>, std::integral_constant<int, 13>>;
48
49 static_assert(
50 !is_error<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
51 "always13 should accept x"
52 );
53
54 static_assert(
55 std::is_same<
56 get_result<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type,
57 std::integral_constant<int, 13>
58 >::type::value,
59 "the result of parsing should be the integral_constant type"
60 );
61
62 static_assert(
63 is_error<always13::apply<BOOST_METAPARSE_STRING("y"), start>>::type::value,
64 "always13 should reject characters other than x"
65 );
66
67 [endsect]
68