[#accept_when] [section accept_when] [h1 Synopsis] template struct accept_when; This is a [link parser_combinator parser combinator]. [table Arguments [[Name] [Type]] [[`P`] [[link parser parser]]] [[`Pred`] [[link predicate predicate]]] [[`Msg`] [[link parsing_error_message parsing error message]]] ] [h1 Description] It parses the input with `P`. When `P` rejects the input, `accept_when` rejects it as well. When `P` accepts it, `accept_when` evaluates `Pred` with the result of parsing the input with `P`. When `Pred` returns `true`, `accept_when` accepts the input and the result of parsing will be what `P` returned. Otherwise `accept_when` rejects the input and `Msg` is used as the error reason. [h1 Header] #include [h1 Expression semantics] For any `p` parser, `pred` predicate, `msg` parsing error message, `s` compile-time string and `pos` source position accept_wheni::apply::type is equivalent to p::apply::type when `p::apply` doesn't return an error and `pred::apply>>::type` is `true`. Otherwise it is equivalent to fail [h1 Example] #include #include #include #include #include #include #include #include using namespace boost::metaparse; BOOST_METAPARSE_DEFINE_ERROR(digit_expected, "Digit expected"); using accept_digit = accept_when, digit_expected>; static_assert( !is_error< accept_digit::apply >::type::value, "accept_digit should accept a digit" ); static_assert( get_result< accept_digit::apply >::type::value == '0', "the result of parsing should be the character value" ); static_assert( is_error< accept_digit::apply >::type::value, "accept_digit should reject a character that is not a digit" ); [endsect]