6 template <class P, class T, class F>
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`T`] [[link metaprogramming_value template metaprogramming value]]]
15 [[`F`] [[link metaprogramming_value template metaprogramming value]]]
20 `if_` always accepts the input string. The result of parsing is `T`, when `P`
21 accepts the input and `F` otherwise.
25 #include <boost/metaparse/if_.hpp>
27 [h1 Expression semantics]
29 For any `p` parser, `t` and `f` classes the following are equivalent:
33 one_of<last_of<p, return_<t>>, return_<f>>
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>
43 #include <type_traits>
45 using namespace boost::metaparse;
47 using int11 = std::integral_constant<int, 11>;
48 using int13 = std::integral_constant<int, 13>;
52 if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("1234"), start>
54 "When the int_ parser succeeds, the result of parsing should be 11"
59 if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("foo"), start>
61 "When the int_ parser fails, the result of parsing should be 13"