digit_val.qbk 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [#digit_val]
  2. [section digit_val]
  3. [h1 Synopsis]
  4. struct digit_val;
  5. This is a [link parser parser].
  6. [h1 Description]
  7. It accepts one character in the range `0-9`. The result of the parser is the
  8. value represented by the accepted character.
  9. [h1 Header]
  10. #include <boost/metaparse/digit_val.hpp>
  11. [h1 Expression semantics]
  12. The following are equivalent:
  13. digit_val
  14. transform<digit, util::digit_to_int<>>
  15. [h1 Example]
  16. #include <boost/metaparse/digit_val.hpp>
  17. #include <boost/metaparse/start.hpp>
  18. #include <boost/metaparse/string.hpp>
  19. #include <boost/metaparse/is_error.hpp>
  20. #include <boost/metaparse/get_result.hpp>
  21. using namespace boost::metaparse;
  22. static_assert(
  23. !is_error<digit_val::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
  24. "digit_val should accept a digit"
  25. );
  26. static_assert(
  27. is_error<digit_val::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
  28. "digit_val should reject a character"
  29. );
  30. static_assert(
  31. get_result<
  32. digit_val::apply<BOOST_METAPARSE_STRING("0"), start>
  33. >::type::value == 0,
  34. "the result of parsing should be the int value"
  35. );
  36. [endsect]