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