int_.qbk 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [#int_]
  2. [section int_]
  3. [h1 Synopsis]
  4. struct int_;
  5. This is a [link parser parser].
  6. [h1 Description]
  7. It accepts a non-empty sequence of characters in the range `0-9`. The result of
  8. the parser is the decimal value represented by the accepted character sequence.
  9. [h1 Header]
  10. #include <boost/metaparse/int_.hpp>
  11. [h1 Expression semantics]
  12. The following are equivalent:
  13. int_
  14. foldl1<
  15. digit_val,
  16. boost::mpl::int_<0>,
  17. boost::mpl::lambda<
  18. boost::mpl::plus<
  19. boost::mpl::times<boost::mpl::_2, boost::mpl::int_<10>>,
  20. boost::mpl::_1
  21. >
  22. >::type
  23. >
  24. [h1 Example]
  25. #include <boost/metaparse/int_.hpp>
  26. #include <boost/metaparse/string.hpp>
  27. #include <boost/metaparse/start.hpp>
  28. #include <boost/metaparse/is_error.hpp>
  29. #include <boost/metaparse/get_result.hpp>
  30. using namespace boost::metaparse;
  31. static_assert(
  32. get_result<
  33. int_::apply<BOOST_METAPARSE_STRING("13"), start>
  34. >::type::value == 13,
  35. "It should parse an integer value"
  36. );
  37. static_assert(
  38. is_error<int_::apply<BOOST_METAPARSE_STRING("six"), start>>::type::value,
  39. "It should reject the input if it is not a number"
  40. );
  41. [endsect]