[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]