[#foldr] [section foldr] [h1 Synopsis] template struct foldr; This is a [link parser_combinator parser combinator]. [table Arguments [[Name] [Type]] [[`P`] [[link parser parser]]] [[`State`] [[link metaprogramming_value template metaprogramming value]]] [[`BackwardOp`] [[link metafunction_class template metafunction class] taking two arguments]] ] [h1 Description] `foldr` applies `P` on the input string repeatedly as long as `P` accepts the input. The result of parsing is equivalent to `boost::reverse_fold`, where `Sequence` is the sequence of the results of the applications of `P`. When `P` rejects the input for the first time, `foldr` still accepts the input and the result of parsing is `State`. Here is a diagram showing how `foldr` works by example: using int_token = token; using sum_op = mpl::lambda>::type; [$images/metaparse/foldr_diag1.png [width 70%]] Further details can be found in the [link introducing-foldr Introducing foldr] section of the [link manual User Manual]. [h1 Header] #include [h1 Expression semantics] For any `p` parser, `t` class, `f` metafunction class taking two arguments, `s` compile-time string and `pos` source position foldr::apply is equivalent to return_::apply when `p::apply` returns an error. It is f::apply< get_result< foldr::apply< get_remaining>, get_position> > >::type, get_result>::type > otherwise. [h1 Example] #include #include #include #include #include #include #include #include using namespace boost::metaparse; using int_token = token; using sum_op = boost::mpl::lambda>::type; using ints = foldr, sum_op>; static_assert( get_result< ints::apply >::type::value == 48, "ints should sum the numbers" ); static_assert( get_result< ints::apply >::type::value == 0, "the sum of no elements is 0" ); [endsect]