6 template <class N, class P0, /* ... */, class Pk>
9 This is a [link parser_combinator parser combinator].
13 [[`N`] [[link boxed_value boxed] integer value in the range `[0..k]`]]
14 [[`P0`..`Pk`] [[link parser parser]s]]
19 `nth_of` applies the `P0` .. `Pk` parsers in sequence. It accepts an input when
20 all of these parsers accept it. The result of parsing is the result of the `N`.
23 The maximum number of parsers `nth_of` accepts can be specified with the
24 `BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE` macro. Its default value is `5`.
28 #include <boost/metaparse/nth_of.hpp>
30 [h1 Expression semantics]
32 For any `p0`, ..., `pn` parsers and `k` boxed integer value the following are
35 nth_of<k, p0, ..., pn>
37 nth_of_c<k::type::value, p0, ..., pn>
41 #include <boost/metaparse/nth_of.hpp>
42 #include <boost/metaparse/int_.hpp>
43 #include <boost/metaparse/lit_c.hpp>
44 #include <boost/metaparse/token.hpp>
45 #include <boost/metaparse/start.hpp>
46 #include <boost/metaparse/string.hpp>
47 #include <boost/metaparse/is_error.hpp>
48 #include <boost/metaparse/get_result.hpp>
50 #include <type_traits>
52 using namespace boost::metaparse;
54 using int_token = token<int_>;
55 using left_paren_token = token<lit_c<'('>>;
56 using right_paren_token = token<lit_c<')'>>;
60 std::integral_constant<int, 1>,
61 left_paren_token, int_token, right_paren_token
66 int_in_parens::apply<BOOST_METAPARSE_STRING("(13)"), start>
68 "it should return the result of the second parser"
73 int_in_parens::apply<BOOST_METAPARSE_STRING("13"), start>
75 "it should reject the input when there are no parens"
80 int_in_parens::apply<BOOST_METAPARSE_STRING("(13"), start>
82 "it should reject the input when there is no closing paren"