1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- [#if_]
- [section if_]
- [h1 Synopsis]
- template <class P, class T, class F>
- struct if_;
- This is a [link parser_combinator parser combinator].
- [table Arguments
- [[Name] [Type]]
- [[`P`] [[link parser parser]]]
- [[`T`] [[link metaprogramming_value template metaprogramming value]]]
- [[`F`] [[link metaprogramming_value template metaprogramming value]]]
- ]
- [h1 Description]
- `if_` always accepts the input string. The result of parsing is `T`, when `P`
- accepts the input and `F` otherwise.
- [h1 Header]
- #include <boost/metaparse/if_.hpp>
- [h1 Expression semantics]
- For any `p` parser, `t` and `f` classes the following are equivalent:
- if_<p, t, f>
-
- one_of<last_of<p, return_<t>>, return_<f>>
- [h1 Example]
- #include <boost/metaparse/if_.hpp>
- #include <boost/metaparse/int_.hpp>
- #include <boost/metaparse/string.hpp>
- #include <boost/metaparse/start.hpp>
- #include <boost/metaparse/get_result.hpp>
-
- #include <type_traits>
-
- using namespace boost::metaparse;
-
- using int11 = std::integral_constant<int, 11>;
- using int13 = std::integral_constant<int, 13>;
-
- static_assert(
- get_result<
- if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("1234"), start>
- >::type::value == 11,
- "When the int_ parser succeeds, the result of parsing should be 11"
- );
-
- static_assert(
- get_result<
- if_<int_, int11, int13>::apply<BOOST_METAPARSE_STRING("foo"), start>
- >::type::value == 13,
- "When the int_ parser fails, the result of parsing should be 13"
- );
- [endsect]
|