8 This is a [link parser parser].
12 `one_char` accepts one character. The result of parsing is the accepted
13 character. It fails for empty input.
17 #include <boost/metaparse/one_char.hpp>
19 [h1 Expression semantics]
21 For any `s` non-empty compile-time string and `pos` source position the
22 following are equivalent
24 get_result<one_char::apply<s, pos>>
28 get_remaining<one_char::apply<s, pos>>
30 boost::mpl::pop_front<s>
32 The value of `get_position<one_char::apply<s, pos>>` depends on the first
33 character of the sequence and the value of the one parsed before that (which is
34 stored in the source position). `one_char` updates the source position's `col`
35 and `line` values based on the new line characters. It detects Linux (`\n`),
36 Windows (`\r\n`) and Mac (`\r`) line endings.
38 `one_char::apply<BOOST_METAPARSE_STRING(""), pos>` returns an error for every
39 `pos` source position.
43 #include <boost/metaparse/one_char.hpp>
44 #include <boost/metaparse/start.hpp>
45 #include <boost/metaparse/string.hpp>
46 #include <boost/metaparse/get_result.hpp>
47 #include <boost/metaparse/get_remaining.hpp>
48 #include <boost/metaparse/is_error.hpp>
50 #include <type_traits>
52 using namespace boost::metaparse;
56 one_char::apply<BOOST_METAPARSE_STRING("foo"), start>
57 >::type::value == 'f',
58 "the result of parsing should be the first character of the input"
63 BOOST_METAPARSE_STRING("oo"),
64 get_remaining<one_char::apply<BOOST_METAPARSE_STRING("foo"), start>>::type
66 "one_char should consume the first character of the input"
70 is_error<one_char::apply<BOOST_METAPARSE_STRING(""), start>>::type::value,
71 "it should return an error for empty input"