metaparse/doc/int_.qbk
2015-07-19 09:53:35 +02:00

60 lines
1.2 KiB
Plaintext

[#int_]
[section int_]
[h1 Synopsis]
struct int_;
This is a [link parser parser].
[h1 Description]
It accepts a non-empty sequence of characters in the range `0-9`. The result of
the parser is the decimal value represented by the accepted character sequence.
[h1 Header]
#include <boost/metaparse/int_.hpp>
[h1 Expression semantics]
The following are equivalent:
int_
foldl1<
digit_val,
boost::mpl::int_<0>,
boost::mpl::lambda<
boost::mpl::plus<
boost::mpl::times<boost::mpl::_2, boost::mpl::int_<10>>,
boost::mpl::_1
>
>::type
>
[h1 Example]
#include <boost/metaparse/int_.hpp>
#include <boost/metaparse/string.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/get_result.hpp>
using namespace boost::metaparse;
static_assert(
get_result<
int_::apply<BOOST_METAPARSE_STRING("13"), start>
>::type::value == 13,
"It should parse an integer value"
);
static_assert(
is_error<int_::apply<BOOST_METAPARSE_STRING("six"), start>>::type::value,
"It should reject the input if it is not a number"
);
[endsect]