[#optional] [section optional] [h1 Synopsis] template struct optional; This is a [link parser_combinator parser combinator]. [table Arguments [[Name] [Type]] [[`P`] [[link parser parser]]] [[`Default`] [[link metaprogramming_value template metaprogramming value]]] ] [h1 Description] It tries parsing the input with `P`. When `P` succeeds, the result of parsing is the result of `P`. Otherwise no characters are consumed and the result of parsing is `Default`. [h1 Header] #include [h1 Expression semantics] For any `p` [link parser parser] and `d` [link metaprogramming_value template metaprogramming value] optional is equivalent to one_of> [h1 Example] #include #include #include #include #include #include #include #include #include #include #include #include using namespace boost::metaparse; using complex_number = sequence< // Real int_, // Imaginary optional< middle_of, int_, lit_c<'i'>>, boost::mpl::int_<0> > > ; static_assert( boost::mpl::equal< boost::mpl::vector_c, get_result< complex_number::apply >::type, boost::mpl::equal_to >::type::value, "No imaginary" ); static_assert( boost::mpl::equal< boost::mpl::vector_c, get_result< complex_number::apply >::type, boost::mpl::equal_to >::type::value, "0 as imaginary" ); static_assert( boost::mpl::equal< boost::mpl::vector_c, get_result< complex_number::apply >::type, boost::mpl::equal_to >::type::value, "Non-null imaginary" ); [endsect]