Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

range_c

Synopsis

template <char From, char To>
struct range_c;

This is a parser.

Table 69. Arguments

Name

Type

From

character value

To

character value


Description

range_c accepts one character in the range [From..To]. The result of the parser is the accepted character.

Header

#include <boost/metaparse/range_c.hpp>

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
>

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"
);

PrevUpHomeNext