Home | Libraries | People | FAQ | More |
template <class P, int N> struct iterate_c;
This is a parser combinator.
It applies P
on the input
string N
times. The result
of parsing is a sequence of the results of the individual applications
of P
. P
has to accept the input N
times for iterate_c
to
accept it.
#include <boost/metaparse/iterate_c.hpp>
For any p
parser, n
integer value the following are equivalent:
iterate_c<p, n> sequence< p, // 1. p, // 2. // ... p // n. >
#include <boost/metaparse/iterate_c.hpp> #include <boost/metaparse/digit.hpp> #include <boost/metaparse/string.hpp> #include <boost/metaparse/start.hpp> #include <boost/metaparse/get_result.hpp> #include <boost/metaparse/is_error.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/equal.hpp> #include <boost/mpl/char.hpp> using namespace boost::metaparse; static_assert( boost::mpl::equal< boost::mpl::vector< boost::mpl::char_<'1'>, boost::mpl::char_<'2'>, boost::mpl::char_<'3'> >, get_result< iterate_c<digit, 3>::apply<BOOST_METAPARSE_STRING("123"), start> >::type >::type::value, "the result should be the sequence of the individual applications of digit" ); static_assert( boost::mpl::equal< boost::mpl::vector< boost::mpl::char_<'1'>, boost::mpl::char_<'2'>, boost::mpl::char_<'3'> >, get_result< iterate_c<digit, 3>::apply<BOOST_METAPARSE_STRING("1234"), start> >::type >::type::value, "only three iterations should be made" ); static_assert( is_error< iterate_c<digit, 3>::apply<BOOST_METAPARSE_STRING("12"), start> >::type::value, "it should fail when digit can not be applied three times" );