Home | Libraries | People | FAQ | More |
struct digit;
This is a parser.
Parser accepting one character in the range 0-9
. The result
of the parser is the accepted character.
#include <boost/metaparse/digit.hpp>
The following are equivalent:
digit accept_when<one_char, util::is_digit, error::digit_expected>
#include <boost/metaparse/digit.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; static_assert( !is_error<digit::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value, "digit should accept a digit" ); static_assert( is_error<digit::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value, "digit should reject a character" ); static_assert( get_result< digit::apply<BOOST_METAPARSE_STRING("0"), start> >::type::value == '0', "the result of parsing should be the character value" );