diff --git a/doc/x3/quick_reference.qbk b/doc/x3/quick_reference.qbk index 76c5bcb745..2ab15a6921 100644 --- a/doc/x3/quick_reference.qbk +++ b/doc/x3/quick_reference.qbk @@ -298,7 +298,7 @@ a: vector, b: vector --> (a > b): vector``]] [[__x3_alternative__ (`a | b`)] [``a: A, b: B --> (a | b): variant a: A, b: Unused --> (a | b): optional -a: A, b: B, c: Unused --> (a | b | c): optional > +a: A, b: B, c: Unused --> (a | b | c): variant a: Unused, b: B --> (a | b): optional a: Unused, b: Unused --> (a | b): Unused a: A, b: A --> (a | b): A``]] diff --git a/include/boost/spirit/home/x3/operator/alternative.hpp b/include/boost/spirit/home/x3/operator/alternative.hpp index aeb6998ba4..8d3ef26612 100644 --- a/include/boost/spirit/home/x3/operator/alternative.hpp +++ b/include/boost/spirit/home/x3/operator/alternative.hpp @@ -7,12 +7,13 @@ #if !defined(BOOST_SPIRIT_X3_ALTERNATIVE_JAN_07_2013_1131AM) #define BOOST_SPIRIT_X3_ALTERNATIVE_JAN_07_2013_1131AM -#include #include #include - +#include #include +#include + namespace boost { namespace spirit { namespace x3 { template @@ -53,11 +54,96 @@ namespace boost { namespace spirit { namespace x3 } }}} + +namespace boost { namespace spirit { namespace x3 { namespace detail +{ + template + struct add_alternative_types_impl; + + template typename Seq, typename... Ts> + struct add_alternative_types_impl> + { + using type = Seq; + }; + + template typename Seq, typename... Ts, typename U, typename... Us> + struct add_alternative_types_impl, U, Us...> + { + using next_sequence = conditional_t::template contains, + Seq, + conditional_t, unused_type>, + typename Seq::template prepend, + typename Seq::template append + > + >; + + using type = typename add_alternative_types_impl::type; + }; + + template + using add_alternative_types = typename add_alternative_types_impl::type; + + template + struct merge_types_of_alternative_impl; + + template