6 template <class P, class N>
9 This is a [link parser_combinator parser combinator].
13 [[`P`] [[link parser parser]]]
14 [[`N`] [[link boxed_value boxed] non-negative integer value]]
19 It applies `P` on the input string `N` times. The result of parsing is a
20 sequence of the results of the individual applications of `P`. `P` has to accept
21 the input `N` times for `iterate` to accept it.
25 #include <boost/metaparse/iterate.hpp>
27 [h1 Expression semantics]
29 For any `p` parser, `n` wrapped integer the following are equivalent:
33 iterate_c<p, n::type::value>
37 #include <boost/metaparse/iterate.hpp>
38 #include <boost/metaparse/digit.hpp>
39 #include <boost/metaparse/string.hpp>
40 #include <boost/metaparse/start.hpp>
41 #include <boost/metaparse/get_result.hpp>
42 #include <boost/metaparse/is_error.hpp>
44 #include <boost/mpl/vector.hpp>
45 #include <boost/mpl/equal.hpp>
46 #include <boost/mpl/char.hpp>
48 #include <type_traits>
50 using namespace boost::metaparse;
55 boost::mpl::char_<'1'>,
56 boost::mpl::char_<'2'>,
57 boost::mpl::char_<'3'>
60 iterate<digit, std::integral_constant<int, 3>>::apply<
61 BOOST_METAPARSE_STRING("123"),
66 "the result should be the sequence of the individual applications of digit"
72 boost::mpl::char_<'1'>,
73 boost::mpl::char_<'2'>,
74 boost::mpl::char_<'3'>
77 iterate<digit, std::integral_constant<int, 3>>::apply<
78 BOOST_METAPARSE_STRING("1234"),
83 "only three iterations should be made"
88 iterate<digit, std::integral_constant<int, 3>>::apply<
89 BOOST_METAPARSE_STRING("12"),
93 "it should fail when digit can not be applied three times"