1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- [#range_c]
- [section range_c]
- [h1 Synopsis]
- template <char From, char To>
- struct range_c;
- This is a [link parser parser].
- [table Arguments
- [[Name] [Type]]
- [[`From`] [character value]]
- [[`To`] [character value]]
- ]
- [h1 Description]
- `range_c` accepts one character in the range `[From..To]`. The result of the
- parser is the accepted character.
- [h1 Header]
- #include <boost/metaparse/range_c.hpp>
- [h1 Expression semantics]
- For any `A`, `B` characters the following are equivalent:
- range_c<A, B>
-
- accept_when<
- one_char,
- util::in_range_c<char, A, B>,
- errors::unexpected_character
- >
- [h1 Example]
- #include <boost/metaparse/range_c.hpp>
- #include <boost/metaparse/start.hpp>
- #include <boost/metaparse/string.hpp>
- #include <boost/metaparse/is_error.hpp>
- #include <boost/metaparse/get_result.hpp>
-
- using namespace boost::metaparse;
-
- using one_digit = range_c<'0', '9'>;
-
- static_assert(
- !is_error<one_digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
- "one_digit should accept a digit"
- );
-
- static_assert(
- is_error<one_digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
- "one_digit should reject a value outside of ['0'..'9']"
- );
-
- static_assert(
- get_result<
- one_digit::apply<BOOST_METAPARSE_STRING("0"), start>
- >::type::value == '0',
- "the result of parsing should be the character value"
- );
- [endsect]
|