[#foldl_start_with_parser] [section foldl_start_with_parser] [h1 Synopsis] template struct foldl_start_with_parser; This is a [link parser_combinator parser combinator]. [table Arguments [[Name] [Type]] [[`P`] [[link parser parser]]] [[`StateP`] [[link parser parser]]] [[`ForwardOp`] [[link metafunction_class template metafunction class] taking two arguments]] ] [h1 Description] The same as [link foldl `foldl`], but before folding it applies a parser, `StateP` on the input. If it fails, `foldl_start_with_parser` fails. If it succeeds, `foldl_start_with_parser` works as `foldl` taking the result of `StateP` as the initial state. Here is a diagram showing how `foldl_start_with_parser` works by example: using int_token = token; using plus_token = token>; using plus_int = last_of; using sum_op = mpl::lambda>::type; [$images/metaparse/foldl_start_with_parser_diag1.png [width 70%]] Further details can be found in the [link introducing-foldl_start_with_parser Introducing foldl_start_with_parser] section of the [link manual User Manual]. [h1 Header] #include [h1 Expression semantics] For any `p` parser, `pt` class, `f` metafunction class taking two arguments, `s` compile-time string and `pos` source position foldl_start_with_parser::apply is equivalent to pt::apply when the above expression returns a parsing error. It is foldl>::type, f>::apply< get_remaining>::type, get_position>::type > otherwise. [h1 Example] #include #include #include #include #include #include #include #include #include #include #include using namespace boost::metaparse; using int_token = token; using plus_token = token>; using plus_int = last_of; using sum_op = boost::mpl::lambda>::type; using ints = foldl_start_with_parser; static_assert( get_result< ints::apply >::type::value == 48, "ints should sum the numbers" ); static_assert( is_error>::type::value, "when no numbers are provided, it should be an error" ); [endsect]