68 lines
1.5 KiB
Plaintext
68 lines
1.5 KiB
Plaintext
[#always_c]
|
|
[section always_c]
|
|
|
|
[h1 Synopsis]
|
|
|
|
template <char C, class T>
|
|
struct always_c;
|
|
|
|
This is a [link parser_combinator parser combinator].
|
|
|
|
[table Arguments
|
|
[[Name] [Type]]
|
|
[[`C`] [character]]
|
|
[[`T`] [[link metaprogramming_value template metaprogramming value]]]
|
|
]
|
|
|
|
[h1 Description]
|
|
|
|
It accepts inputs beginning with the `C` character. It consumes that character
|
|
and the result of parsing is `T`. Other inputs as rejected.
|
|
|
|
[h1 Header]
|
|
|
|
#include <boost/metaparse/always_c.hpp>
|
|
|
|
[h1 Expression semantics]
|
|
|
|
For any `c` character and `t` class the following are equivalent:
|
|
|
|
always_c<c, t>
|
|
|
|
always<lit_c<c>, t>
|
|
|
|
[h1 Example]
|
|
|
|
#include <boost/metaparse/always_c.hpp>
|
|
#include <boost/metaparse/start.hpp>
|
|
#include <boost/metaparse/string.hpp>
|
|
#include <boost/metaparse/is_error.hpp>
|
|
#include <boost/metaparse/get_result.hpp>
|
|
|
|
#include <type_traits>
|
|
|
|
using namespace boost::metaparse;
|
|
|
|
using always13 = always_c<'x', std::integral_constant<int, 13>>;
|
|
|
|
static_assert(
|
|
!is_error<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
|
|
"always13 should accept x"
|
|
);
|
|
|
|
static_assert(
|
|
std::is_same<
|
|
get_result<always13::apply<BOOST_METAPARSE_STRING("x"), start>>::type,
|
|
std::integral_constant<int, 13>
|
|
>::type::value,
|
|
"the result of parsing should be the integral_constant type"
|
|
);
|
|
|
|
static_assert(
|
|
is_error<always13::apply<BOOST_METAPARSE_STRING("y"), start>>::type::value,
|
|
"always13 should reject characters other than x"
|
|
);
|
|
|
|
[endsect]
|
|
|