1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- [#return_]
- [section return_]
- [h1 Synopsis]
- template <class C>
- struct return_;
- This is a [link parser parser].
- [table Arguments
- [[Name] [Type]]
- [[`C`] [[link metaprogramming_value template metaprogramming value]]]
- ]
- [h1 Description]
- `return_` accepts every input. The result of parsing is `C`, the remaining
- string is the input string.
- [h1 Header]
- #include <boost/metaparse/return_.hpp>
- [h1 Expression semantics]
- For any `c` class, `s` compile-time string and `pos` source position the
- following are equivalent
- get_result<return_<c>::apply<s, pos>>::type
-
- c
- get_remaining<return_<c>::apply<s, pos>>::type
-
- s
- get_position<return_<c>::apply<s, pos>>::type
-
- pos
- [h1 Example]
- #include <boost/metaparse/return_.hpp>
- #include <boost/metaparse/int_.hpp>
- #include <boost/metaparse/one_of.hpp>
- #include <boost/metaparse/start.hpp>
- #include <boost/metaparse/string.hpp>
- #include <boost/metaparse/get_result.hpp>
-
- #include <type_traits>
-
- using namespace boost::metaparse;
-
- using default_value = std::integral_constant<int, 13>;
-
- using optional_number = one_of<int_, return_<default_value>>;
-
- static_assert(
- get_result<
- optional_number::apply<BOOST_METAPARSE_STRING("11"), start>
- >::type::value == 11,
- "when a number is provided, it is the result of parsing"
- );
-
- static_assert(
- get_result<
- optional_number::apply<BOOST_METAPARSE_STRING(""), start>
- >::type::value == 13,
- "when no number is provided, the default value is the result of parsing"
- );
- [endsect]
|