diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index ad92069..943ab07 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -32,8 +32,6 @@ namespace boost namespace variant2 { -using namespace boost::mp11; - // bad_variant_access class bad_variant_access: public std::exception @@ -91,7 +89,7 @@ template /*inline*/ constexpr std::size_t variant_size_v = variant_siz #endif -template struct variant_size>: mp_size> +template struct variant_size>: mp11::mp_size> { }; @@ -112,18 +110,18 @@ template struct variant_alternative_impl template struct variant_alternative_impl, true> { - using type = mp_at_c, I>; + using type = mp11::mp_at_c, I>; }; -template struct variant_alternative_impl const, true>: std::add_const< mp_at_c, I> > +template struct variant_alternative_impl const, true>: std::add_const< mp11::mp_at_c, I> > { }; -template struct variant_alternative_impl volatile, true>: std::add_volatile< mp_at_c, I> > +template struct variant_alternative_impl volatile, true>: std::add_volatile< mp11::mp_at_c, I> > { }; -template struct variant_alternative_impl const volatile, true>: std::add_cv< mp_at_c, I> > +template struct variant_alternative_impl const volatile, true>: std::add_cv< mp11::mp_at_c, I> > { }; @@ -154,7 +152,7 @@ template struct variant_alternative namespace detail { -template using var_alt_impl = mp_invoke_q>; +template using var_alt_impl = mp11::mp_invoke_q>; } // namespace detail @@ -162,19 +160,19 @@ template struct variant_alternative { }; -template struct variant_alternative: mp_defer< variant2::detail::var_alt_impl, mp_size_t, T, mp_quote_trait> +template struct variant_alternative: mp11::mp_defer< variant2::detail::var_alt_impl, mp11::mp_size_t, T, mp11::mp_quote_trait> { }; -template struct variant_alternative: mp_defer< variant2::detail::var_alt_impl, mp_size_t, T, mp_quote_trait> +template struct variant_alternative: mp11::mp_defer< variant2::detail::var_alt_impl, mp11::mp_size_t, T, mp11::mp_quote_trait> { }; -template struct variant_alternative: mp_defer< variant2::detail::var_alt_impl, mp_size_t, T, mp_quote_trait> +template struct variant_alternative: mp11::mp_defer< variant2::detail::var_alt_impl, mp11::mp_size_t, T, mp11::mp_quote_trait> { }; -template struct variant_alternative>: mp_defer, mp_size_t> +template struct variant_alternative>: mp11::mp_defer, mp11::mp_size_t> { }; @@ -184,8 +182,8 @@ template struct variant_alternative> template constexpr bool holds_alternative( variant const& v ) noexcept { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - return v.index() == mp_find, U>::value; + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + return v.index() == mp11::mp_find, U>::value; } // get (index) @@ -193,7 +191,7 @@ template constexpr bool holds_alternative( variant co template constexpr variant_alternative_t>& get(variant& v) { static_assert( I < sizeof...(T), "Index out of bounds" ); - return (void)( v.index() != I? throw bad_variant_access(): 0 ), v._get_impl( mp_size_t() ); + return (void)( v.index() != I? throw bad_variant_access(): 0 ), v._get_impl( mp11::mp_size_t() ); } template constexpr variant_alternative_t>&& get(variant&& v) @@ -202,12 +200,12 @@ template constexpr variant_alternative_t() ) ); + return (void)( v.index() != I? throw bad_variant_access(): 0 ), std::move( v._get_impl( mp11::mp_size_t() ) ); #else if( v.index() != I ) throw bad_variant_access(); - return std::move( v._get_impl( mp_size_t() ) ); + return std::move( v._get_impl( mp11::mp_size_t() ) ); #endif } @@ -215,7 +213,7 @@ template constexpr variant_alternative_t constexpr variant_alternative_t> const& get(variant const& v) { static_assert( I < sizeof...(T), "Index out of bounds" ); - return (void)( v.index() != I? throw bad_variant_access(): 0 ), v._get_impl( mp_size_t() ); + return (void)( v.index() != I? throw bad_variant_access(): 0 ), v._get_impl( mp11::mp_size_t() ); } template constexpr variant_alternative_t> const&& get(variant const&& v) @@ -224,12 +222,12 @@ template constexpr variant_alternative_t() ) ); + return (void)( v.index() != I? throw bad_variant_access(): 0 ), std::move( v._get_impl( mp11::mp_size_t() ) ); #else if( v.index() != I ) throw bad_variant_access(); - return std::move( v._get_impl( mp_size_t() ) ); + return std::move( v._get_impl( mp11::mp_size_t() ) ); #endif } @@ -238,18 +236,18 @@ template constexpr variant_alternative_t constexpr U& get(variant& v) { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; return (void)( v.index() != I::value? throw bad_variant_access(): 0 ), v._get_impl( I() ); } template constexpr U&& get(variant&& v) { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; #if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) @@ -265,18 +263,18 @@ template constexpr U&& get(variant&& v) template constexpr U const& get(variant const& v) { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; return (void)( v.index() != I::value? throw bad_variant_access(): 0 ), v._get_impl( I() ); } template constexpr U const&& get(variant const&& v) { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; #if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) @@ -295,29 +293,29 @@ template constexpr U const&& get(variant const&& v) template constexpr typename std::add_pointer>>::type get_if(variant* v) noexcept { static_assert( I < sizeof...(T), "Index out of bounds" ); - return v && v->index() == I? &v->_get_impl( mp_size_t() ): 0; + return v && v->index() == I? &v->_get_impl( mp11::mp_size_t() ): 0; } template constexpr typename std::add_pointer>>::type get_if(variant const * v) noexcept { static_assert( I < sizeof...(T), "Index out of bounds" ); - return v && v->index() == I? &v->_get_impl( mp_size_t() ): 0; + return v && v->index() == I? &v->_get_impl( mp11::mp_size_t() ): 0; } template constexpr typename std::add_pointer::type get_if(variant* v) noexcept { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; return v && v->index() == I::value? &v->_get_impl( I() ): 0; } template constexpr typename std::add_pointer::type get_if(variant const * v) noexcept { - static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); + static_assert( mp11::mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); - using I = mp_find, U>; + using I = mp11::mp_find, U>; return v && v->index() == I::value? &v->_get_impl( I() ): 0; } @@ -331,19 +329,19 @@ namespace detail #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 -template struct is_trivially_copy_constructible: mp_bool::value && std::has_trivial_copy_constructor::value> +template struct is_trivially_copy_constructible: mp11::mp_bool::value && std::has_trivial_copy_constructor::value> { }; -template struct is_trivially_copy_assignable: mp_bool::value && std::has_trivial_copy_assign::value> +template struct is_trivially_copy_assignable: mp11::mp_bool::value && std::has_trivial_copy_assign::value> { }; -template struct is_trivially_move_constructible: mp_bool::value && std::is_trivial::value> +template struct is_trivially_move_constructible: mp11::mp_bool::value && std::is_trivial::value> { }; -template struct is_trivially_move_assignable: mp_bool::value && std::is_trivial::value> +template struct is_trivially_move_assignable: mp11::mp_bool::value && std::is_trivial::value> { }; @@ -360,23 +358,23 @@ using std::is_trivially_move_assignable; template union variant_storage_impl; -template using variant_storage = variant_storage_impl...>, T...>; +template using variant_storage = variant_storage_impl...>, T...>; template union variant_storage_impl { }; // not all trivially destructible -template union variant_storage_impl +template union variant_storage_impl { T1 first_; variant_storage rest_; - template constexpr explicit variant_storage_impl( mp_size_t<0>, A&&... a ): first_( std::forward(a)... ) + template constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward(a)... ) { } - template constexpr explicit variant_storage_impl( mp_size_t, A&&... a ): rest_( mp_size_t(), std::forward(a)... ) + template constexpr explicit variant_storage_impl( mp11::mp_size_t, A&&... a ): rest_( mp11::mp_size_t(), std::forward(a)... ) { } @@ -384,62 +382,62 @@ template union variant_storage_impl { } - template void emplace( mp_size_t<0>, A&&... a ) + template void emplace( mp11::mp_size_t<0>, A&&... a ) { ::new( &first_ ) T1( std::forward(a)... ); } - template void emplace( mp_size_t, A&&... a ) + template void emplace( mp11::mp_size_t, A&&... a ) { - rest_.emplace( mp_size_t(), std::forward(a)... ); + rest_.emplace( mp11::mp_size_t(), std::forward(a)... ); } - BOOST_CXX14_CONSTEXPR T1& get( mp_size_t<0> ) noexcept { return first_; } - constexpr T1 const& get( mp_size_t<0> ) const noexcept { return first_; } + BOOST_CXX14_CONSTEXPR T1& get( mp11::mp_size_t<0> ) noexcept { return first_; } + constexpr T1 const& get( mp11::mp_size_t<0> ) const noexcept { return first_; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I-1>& get( mp_size_t ) noexcept { return rest_.get( mp_size_t() ); } - template constexpr mp_at_c, I-1> const& get( mp_size_t ) const noexcept { return rest_.get( mp_size_t() ); } + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I-1>& get( mp11::mp_size_t ) noexcept { return rest_.get( mp11::mp_size_t() ); } + template constexpr mp11::mp_at_c, I-1> const& get( mp11::mp_size_t ) const noexcept { return rest_.get( mp11::mp_size_t() ); } }; // all trivially destructible -template union variant_storage_impl +template union variant_storage_impl { T1 first_; variant_storage rest_; - template constexpr explicit variant_storage_impl( mp_size_t<0>, A&&... a ): first_( std::forward(a)... ) + template constexpr explicit variant_storage_impl( mp11::mp_size_t<0>, A&&... a ): first_( std::forward(a)... ) { } - template constexpr explicit variant_storage_impl( mp_size_t, A&&... a ): rest_( mp_size_t(), std::forward(a)... ) + template constexpr explicit variant_storage_impl( mp11::mp_size_t, A&&... a ): rest_( mp11::mp_size_t(), std::forward(a)... ) { } - template void emplace_impl( mp_false, mp_size_t<0>, A&&... a ) + template void emplace_impl( mp11::mp_false, mp11::mp_size_t<0>, A&&... a ) { ::new( &first_ ) T1( std::forward(a)... ); } - template BOOST_CXX14_CONSTEXPR void emplace_impl( mp_false, mp_size_t, A&&... a ) + template BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_size_t, A&&... a ) { - rest_.emplace( mp_size_t(), std::forward(a)... ); + rest_.emplace( mp11::mp_size_t(), std::forward(a)... ); } - template BOOST_CXX14_CONSTEXPR void emplace_impl( mp_true, mp_size_t, A&&... a ) + template BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_true, mp11::mp_size_t, A&&... a ) { - *this = variant_storage_impl( mp_size_t(), std::forward(a)... ); + *this = variant_storage_impl( mp11::mp_size_t(), std::forward(a)... ); } - template BOOST_CXX14_CONSTEXPR void emplace( mp_size_t, A&&... a ) + template BOOST_CXX14_CONSTEXPR void emplace( mp11::mp_size_t, A&&... a ) { - this->emplace_impl( mp_all, variant2::detail::is_trivially_move_assignable...>(), mp_size_t(), std::forward(a)... ); + this->emplace_impl( mp11::mp_all, variant2::detail::is_trivially_move_assignable...>(), mp11::mp_size_t(), std::forward(a)... ); } - BOOST_CXX14_CONSTEXPR T1& get( mp_size_t<0> ) noexcept { return first_; } - constexpr T1 const& get( mp_size_t<0> ) const noexcept { return first_; } + BOOST_CXX14_CONSTEXPR T1& get( mp11::mp_size_t<0> ) noexcept { return first_; } + constexpr T1 const& get( mp11::mp_size_t<0> ) const noexcept { return first_; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I-1>& get( mp_size_t ) noexcept { return rest_.get( mp_size_t() ); } - template constexpr mp_at_c, I-1> const& get( mp_size_t ) const noexcept { return rest_.get( mp_size_t() ); } + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I-1>& get( mp11::mp_size_t ) noexcept { return rest_.get( mp11::mp_size_t() ); } + template constexpr mp11::mp_at_c, I-1> const& get( mp11::mp_size_t ) const noexcept { return rest_.get( mp11::mp_size_t() ); } }; // resolve_overload_* @@ -454,14 +452,14 @@ template<> struct overload<> template struct overload: overload { using overload::operator(); - mp_identity operator()(T1) const; + mp11::mp_identity operator()(T1) const; }; #if BOOST_WORKAROUND( BOOST_MSVC, < 1920 ) template using resolve_overload_type_ = decltype( overload()(std::declval()) ); -template struct resolve_overload_type_impl: mp_defer< resolve_overload_type_, U, T... > +template struct resolve_overload_type_impl: mp11::mp_defer< resolve_overload_type_, U, T... > { }; @@ -473,15 +471,15 @@ template using resolve_overload_type = typename decltype( o #endif -template using resolve_overload_index = mp_find, resolve_overload_type>; +template using resolve_overload_index = mp11::mp_find, resolve_overload_type>; // variant_base -template using can_be_valueless = mp_any..., std::is_nothrow_default_constructible...>; -template using valueless_index = mp_if, monostate>, mp_find, monostate>, mp_find_if, std::is_nothrow_default_constructible>>; +template using can_be_valueless = mp11::mp_any..., std::is_nothrow_default_constructible...>; +template using valueless_index = mp11::mp_if, monostate>, mp11::mp_find, monostate>, mp11::mp_find_if, std::is_nothrow_default_constructible>>; template struct variant_base_impl; // trivially destructible, single buffered -template using variant_base = variant_base_impl...>::value, mp_any...>, can_be_valueless>::value, T...>; +template using variant_base = variant_base_impl...>::value, mp11::mp_any...>, can_be_valueless>::value, T...>; struct none {}; @@ -491,11 +489,11 @@ template struct variant_base_impl int ix_; variant_storage st1_; - constexpr variant_base_impl(): ix_( 0 ), st1_( mp_size_t<0>() ) + constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ) { } - template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp_size_t(), std::forward(a)... ) + template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t(), std::forward(a)... ) { } @@ -504,38 +502,38 @@ template struct variant_base_impl return ix_ - 1; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I>& _get_impl( mp_size_t ) noexcept + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I>& _get_impl( mp11::mp_size_t ) noexcept { size_t const J = I+1; assert( ix_ == J ); - return st1_.get( mp_size_t() ); + return st1_.get( mp11::mp_size_t() ); } - template constexpr mp_at_c, I> const& _get_impl( mp_size_t ) const noexcept + template constexpr mp11::mp_at_c, I> const& _get_impl( mp11::mp_size_t ) const noexcept { // size_t const J = I+1; // assert( ix_ == I+1 ); - return st1_.get( mp_size_t() ); + return st1_.get( mp11::mp_size_t() ); } - template BOOST_CXX14_CONSTEXPR void emplace_impl( mp_true, mp_bool, A&&... a ) + template BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_true, mp11::mp_bool, A&&... a ) { - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = J; } - template BOOST_CXX14_CONSTEXPR void emplace_impl( mp_false, mp_true, A&&... a ) + template BOOST_CXX14_CONSTEXPR void emplace_impl( mp11::mp_false, mp11::mp_true, A&&... a ) { U tmp( std::forward(a)... ); - st1_.emplace( mp_size_t(), std::move(tmp) ); + st1_.emplace( mp11::mp_size_t(), std::move(tmp) ); ix_ = J; } - template void emplace_impl( mp_false, mp_false, A&&... a ) + template void emplace_impl( mp11::mp_false, mp11::mp_false, A&&... a ) { if( can_be_valueless::value ) { @@ -545,12 +543,12 @@ template struct variant_base_impl try { - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = J; } catch( ... ) { - st1_.emplace( mp_size_t() ); + st1_.emplace( mp11::mp_size_t() ); ix_ = K+1; throw; @@ -562,7 +560,7 @@ template struct variant_base_impl U tmp( std::forward(a)... ); - st1_.emplace( mp_size_t(), std::move(tmp) ); + st1_.emplace( mp11::mp_size_t(), std::move(tmp) ); ix_ = J; } } @@ -570,9 +568,9 @@ template struct variant_base_impl template BOOST_CXX14_CONSTEXPR void emplace( A&&... a ) { std::size_t const J = I+1; - using U = mp_at_c, I>; + using U = mp11::mp_at_c, I>; - this->emplace_impl( std::is_nothrow_constructible(), mp_all, variant2::detail::is_trivially_move_assignable...>(), std::forward(a)... ); + this->emplace_impl( std::is_nothrow_constructible(), mp11::mp_all, variant2::detail::is_trivially_move_assignable...>(), std::forward(a)... ); } }; @@ -583,11 +581,11 @@ template struct variant_base_impl variant_storage st1_; variant_storage st2_; - constexpr variant_base_impl(): ix_( 0 ), st1_( mp_size_t<0>() ), st2_( mp_size_t<0>() ) + constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() ) { } - template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp_size_t(), std::forward(a)... ), st2_( mp_size_t<0>() ) + template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t(), std::forward(a)... ), st2_( mp11::mp_size_t<0>() ) { } @@ -596,23 +594,23 @@ template struct variant_base_impl return ix_ >= 0? ix_ - 1: -ix_ - 1; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I>& _get_impl( mp_size_t ) noexcept + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I>& _get_impl( mp11::mp_size_t ) noexcept { size_t const J = I+1; assert( ix_ == J || -ix_ == J ); - constexpr mp_size_t j{}; + constexpr mp11::mp_size_t j{}; return ix_ >= 0? st1_.get( j ): st2_.get( j ); } - template constexpr mp_at_c, I> const& _get_impl( mp_size_t ) const noexcept + template constexpr mp11::mp_at_c, I> const& _get_impl( mp11::mp_size_t ) const noexcept { // size_t const J = I+1; // assert( ix_ == J || -ix_ == J ); // constexpr mp_size_t j{}; - return ix_ >= 0? st1_.get( mp_size_t() ): st2_.get( mp_size_t() ); + return ix_ >= 0? st1_.get( mp11::mp_size_t() ): st2_.get( mp11::mp_size_t() ); } template BOOST_CXX14_CONSTEXPR void emplace( A&&... a ) @@ -621,12 +619,12 @@ template struct variant_base_impl if( ix_ >= 0 ) { - st2_.emplace( mp_size_t(), std::forward(a)... ); + st2_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = -static_cast( J ); } else { - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = J; } } @@ -638,11 +636,11 @@ template struct variant_base_impl int ix_; variant_storage st1_; - constexpr variant_base_impl(): ix_( 0 ), st1_( mp_size_t<0>() ) + constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ) { } - template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp_size_t(), std::forward(a)... ) + template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t(), std::forward(a)... ) { } @@ -657,7 +655,7 @@ template struct variant_base_impl template void operator()( I ) const noexcept { - using U = mp_at, I>; + using U = mp11::mp_at, I>; this_->st1_.get( I() ).~U(); } }; @@ -666,7 +664,7 @@ template struct variant_base_impl { if( ix_ > 0 ) { - mp_with_index<1 + sizeof...(T)>( ix_, _destroy_L1{ this } ); + mp11::mp_with_index<1 + sizeof...(T)>( ix_, _destroy_L1{ this } ); } } @@ -680,34 +678,34 @@ template struct variant_base_impl return ix_ - 1; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I>& _get_impl( mp_size_t ) noexcept + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I>& _get_impl( mp11::mp_size_t ) noexcept { size_t const J = I+1; assert( ix_ == J ); - return st1_.get( mp_size_t() ); + return st1_.get( mp11::mp_size_t() ); } - template constexpr mp_at_c, I> const& _get_impl( mp_size_t ) const noexcept + template constexpr mp11::mp_at_c, I> const& _get_impl( mp11::mp_size_t ) const noexcept { // size_t const J = I+1; // assert( ix_ == J ); - return st1_.get( mp_size_t() ); + return st1_.get( mp11::mp_size_t() ); } template void emplace( A&&... a ) { size_t const J = I+1; - using U = mp_at_c, I>; + using U = mp11::mp_at_c, I>; if( std::is_nothrow_constructible::value ) { _destroy(); - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = J; } else if( can_be_valueless::value ) @@ -720,12 +718,12 @@ template struct variant_base_impl try { - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); ix_ = J; } catch( ... ) { - st1_.emplace( mp_size_t() ); + st1_.emplace( mp11::mp_size_t() ); ix_ = K+1; throw; @@ -739,7 +737,7 @@ template struct variant_base_impl _destroy(); - st1_.emplace( mp_size_t(), std::move(tmp) ); + st1_.emplace( mp11::mp_size_t(), std::move(tmp) ); ix_ = J; } } @@ -752,11 +750,11 @@ template struct variant_base_impl variant_storage st1_; variant_storage st2_; - constexpr variant_base_impl(): ix_( 0 ), st1_( mp_size_t<0>() ), st2_( mp_size_t<0>() ) + constexpr variant_base_impl(): ix_( 0 ), st1_( mp11::mp_size_t<0>() ), st2_( mp11::mp_size_t<0>() ) { } - template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp_size_t(), std::forward(a)... ), st2_( mp_size_t<0>() ) + template constexpr explicit variant_base_impl( I, A&&... a ): ix_( I::value + 1 ), st1_( mp11::mp_size_t(), std::forward(a)... ), st2_( mp11::mp_size_t<0>() ) { } @@ -771,7 +769,7 @@ template struct variant_base_impl template void operator()( I ) const noexcept { - using U = mp_at, I>; + using U = mp11::mp_at, I>; this_->st1_.get( I() ).~U(); } }; @@ -782,7 +780,7 @@ template struct variant_base_impl template void operator()( I ) const noexcept { - using U = mp_at, I>; + using U = mp11::mp_at, I>; this_->st2_.get( I() ).~U(); } }; @@ -791,11 +789,11 @@ template struct variant_base_impl { if( ix_ > 0 ) { - mp_with_index<1 + sizeof...(T)>( ix_, _destroy_L1{ this } ); + mp11::mp_with_index<1 + sizeof...(T)>( ix_, _destroy_L1{ this } ); } else if( ix_ < 0 ) { - mp_with_index<1 + sizeof...(T)>( -ix_, _destroy_L2{ this } ); + mp11::mp_with_index<1 + sizeof...(T)>( -ix_, _destroy_L2{ this } ); } } @@ -809,23 +807,23 @@ template struct variant_base_impl return ix_ >= 0? ix_ - 1: -ix_ - 1; } - template BOOST_CXX14_CONSTEXPR mp_at_c, I>& _get_impl( mp_size_t ) noexcept + template BOOST_CXX14_CONSTEXPR mp11::mp_at_c, I>& _get_impl( mp11::mp_size_t ) noexcept { size_t const J = I+1; assert( ix_ == J || -ix_ == J ); - constexpr mp_size_t j{}; + constexpr mp11::mp_size_t j{}; return ix_ >= 0? st1_.get( j ): st2_.get( j ); } - template constexpr mp_at_c, I> const& _get_impl( mp_size_t ) const noexcept + template constexpr mp11::mp_at_c, I> const& _get_impl( mp11::mp_size_t ) const noexcept { // size_t const J = I+1; // assert( ix_ == J || -ix_ == J ); // constexpr mp_size_t j{}; - return ix_ >= 0? st1_.get( mp_size_t() ): st2_.get( mp_size_t() ); + return ix_ >= 0? st1_.get( mp11::mp_size_t() ): st2_.get( mp11::mp_size_t() ); } template void emplace( A&&... a ) @@ -834,14 +832,14 @@ template struct variant_base_impl if( ix_ >= 0 ) { - st2_.emplace( mp_size_t(), std::forward(a)... ); + st2_.emplace( mp11::mp_size_t(), std::forward(a)... ); _destroy(); ix_ = -static_cast( J ); } else { - st1_.emplace( mp_size_t(), std::forward(a)... ); + st1_.emplace( mp11::mp_size_t(), std::forward(a)... ); _destroy(); ix_ = J; @@ -910,7 +908,7 @@ template struct is_nothrow_swappable_impl_ static constexpr bool value = noexcept(swap(std::declval(), std::declval())); }; -template using is_nothrow_swappable_impl = mp_bool< is_nothrow_swappable_impl_::value >; +template using is_nothrow_swappable_impl = mp11::mp_bool< is_nothrow_swappable_impl_::value >; #else @@ -920,19 +918,19 @@ template using is_nothrow_swappable_impl = typename std::enable_if struct is_swappable: mp_valid +template struct is_swappable: mp11::mp_valid { }; #if BOOST_WORKAROUND( BOOST_MSVC, < 1920 ) -template struct is_nothrow_swappable: mp_eval_if>, mp_false, det2::is_nothrow_swappable_impl, T> +template struct is_nothrow_swappable: mp11::mp_eval_if>, mp11::mp_false, det2::is_nothrow_swappable_impl, T> { }; #else -template struct is_nothrow_swappable: mp_valid +template struct is_nothrow_swappable: mp11::mp_valid { }; @@ -957,15 +955,15 @@ public: // constructors - template> >, E1>> + template> >, E1>> constexpr variant() - noexcept( std::is_nothrow_default_constructible< mp_first> >::value ) - : variant_base( mp_size_t<0>() ) + noexcept( std::is_nothrow_default_constructible< mp11::mp_first> >::value ) + : variant_base( mp11::mp_size_t<0>() ) { } template...>, E1> + class E2 = mp11::mp_if...>, E1> > constexpr variant( variant const& r ) noexcept : variant_base( static_cast(r) ) @@ -988,17 +986,17 @@ private: public: template...>>, E1>, - class E3 = mp_if...>, E1> + class E2 = mp11::mp_if...>>, E1>, + class E3 = mp11::mp_if...>, E1> > variant( variant const& r ) - noexcept( mp_all...>::value ) + noexcept( mp11::mp_all...>::value ) { - mp_with_index( r.index(), L1{ this, r } ); + mp11::mp_with_index( r.index(), L1{ this, r } ); } template...>, E1> + class E2 = mp11::mp_if...>, E1> > constexpr variant( variant && r ) noexcept : variant_base( static_cast(r) ) @@ -1021,13 +1019,13 @@ private: public: template...>>, E1>, - class E3 = mp_if...>, E1> + class E2 = mp11::mp_if...>>, E1>, + class E3 = mp11::mp_if...>, E1> > variant( variant && r ) - noexcept( mp_all...>::value ) + noexcept( mp11::mp_all...>::value ) { - mp_with_index( r.index(), L2{ this, r } ); + mp11::mp_with_index( r.index(), L2{ this, r } ); } template, U>, class E = typename std::enable_if::value>::type> + template, U>, class E = typename std::enable_if::value>::type> constexpr explicit variant( in_place_type_t, A&&... a ): variant_base( I(), std::forward(a)... ) { } - template, U>, class E = typename std::enable_if&, A...>::value>::type> + template, U>, class E = typename std::enable_if&, A...>::value>::type> constexpr explicit variant( in_place_type_t, std::initializer_list il, A&&... a ): variant_base( I(), il, std::forward(a)... ) { } - template, I>, A...>::value>::type> - constexpr explicit variant( in_place_index_t, A&&... a ): variant_base( mp_size_t(), std::forward(a)... ) + template, I>, A...>::value>::type> + constexpr explicit variant( in_place_index_t, A&&... a ): variant_base( mp11::mp_size_t(), std::forward(a)... ) { } - template, I>, std::initializer_list&, A...>::value>::type> - constexpr explicit variant( in_place_index_t, std::initializer_list il, A&&... a ): variant_base( mp_size_t(), il, std::forward(a)... ) + template, I>, std::initializer_list&, A...>::value>::type> + constexpr explicit variant( in_place_index_t, std::initializer_list il, A&&... a ): variant_base( mp11::mp_size_t(), il, std::forward(a)... ) { } // assignment template..., variant2::detail::is_trivially_copy_assignable...>, E1> + class E2 = mp11::mp_if..., variant2::detail::is_trivially_copy_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant const & r ) noexcept { @@ -1095,18 +1093,18 @@ private: public: template..., variant2::detail::is_trivially_copy_assignable...>>, E1>, - class E3 = mp_if..., std::is_copy_assignable...>, E1> + class E2 = mp11::mp_if..., variant2::detail::is_trivially_copy_assignable...>>, E1>, + class E3 = mp11::mp_if..., std::is_copy_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant const & r ) - noexcept( mp_all..., std::is_nothrow_copy_assignable...>::value ) + noexcept( mp11::mp_all..., std::is_nothrow_copy_assignable...>::value ) { - mp_with_index( r.index(), L3{ this, r } ); + mp11::mp_with_index( r.index(), L3{ this, r } ); return *this; } template..., variant2::detail::is_trivially_move_assignable...>, E1> + class E2 = mp11::mp_if..., variant2::detail::is_trivially_move_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant && r ) noexcept { @@ -1137,13 +1135,13 @@ private: public: template..., variant2::detail::is_trivially_move_assignable...>>, E1>, - class E3 = mp_if..., std::is_move_assignable...>, E1> + class E2 = mp11::mp_if..., variant2::detail::is_trivially_move_assignable...>>, E1>, + class E3 = mp11::mp_if..., std::is_move_assignable...>, E1> > variant& operator=( variant && r ) - noexcept( mp_all..., std::is_nothrow_move_assignable...>::value ) + noexcept( mp11::mp_all..., std::is_nothrow_move_assignable...>::value ) { - mp_with_index( r.index(), L4{ this, r } ); + mp11::mp_with_index( r.index(), L4{ this, r } ); return *this; } @@ -1159,7 +1157,7 @@ public: if( index() == I ) { - _get_impl( mp_size_t() ) = std::forward(u); + _get_impl( mp11::mp_size_t() ) = std::forward(u); } else { @@ -1172,35 +1170,35 @@ public: // modifiers template, U>::value == 1 && std::is_constructible::value >::type> + class E = typename std::enable_if< mp11::mp_count, U>::value == 1 && std::is_constructible::value >::type> BOOST_CXX14_CONSTEXPR U& emplace( A&&... a ) { - using I = mp_find, U>; + using I = mp11::mp_find, U>; variant_base::template emplace( std::forward(a)... ); return _get_impl( I() ); } template, U>::value == 1 && std::is_constructible&, A...>::value >::type> + class E = typename std::enable_if< mp11::mp_count, U>::value == 1 && std::is_constructible&, A...>::value >::type> BOOST_CXX14_CONSTEXPR U& emplace( std::initializer_list il, A&&... a ) { - using I = mp_find, U>; + using I = mp11::mp_find, U>; variant_base::template emplace( il, std::forward(a)... ); return _get_impl( I() ); } - template, I>, A...>::value>::type> + template, I>, A...>::value>::type> BOOST_CXX14_CONSTEXPR variant_alternative_t>& emplace( A&&... a ) { variant_base::template emplace( std::forward(a)... ); - return _get_impl( mp_size_t() ); + return _get_impl( mp11::mp_size_t() ); } - template, I>, std::initializer_list&, A...>::value>::type> + template, I>, std::initializer_list&, A...>::value>::type> BOOST_CXX14_CONSTEXPR variant_alternative_t>& emplace( std::initializer_list il, A&&... a ) { variant_base::template emplace( il, std::forward(a)... ); - return _get_impl( mp_size_t() ); + return _get_impl( mp11::mp_size_t() ); } // value status @@ -1225,11 +1223,11 @@ private: public: - void swap( variant& r ) noexcept( mp_all..., variant2::detail::is_nothrow_swappable...>::value ) + void swap( variant& r ) noexcept( mp11::mp_all..., variant2::detail::is_nothrow_swappable...>::value ) { if( index() == r.index() ) { - mp_with_index( index(), L5{ this, r } ); + mp11::mp_with_index( index(), L5{ this, r } ); } else { @@ -1259,7 +1257,7 @@ private: template void operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; ::new( static_cast(this_) ) variant_base( J{}, r._get_impl( i ) ); } }; @@ -1267,11 +1265,11 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > variant( variant const& r ) - noexcept( mp_all...>::value ) + noexcept( mp11::mp_all...>::value ) { - mp_with_index( r.index(), L6{ this, r } ); + mp11::mp_with_index( r.index(), L6{ this, r } ); } private: @@ -1283,7 +1281,7 @@ private: template void operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; ::new( static_cast(this_) ) variant_base( J{}, std::move( r._get_impl( i ) ) ); } }; @@ -1291,23 +1289,23 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > variant( variant && r ) - noexcept( mp_all...>::value ) + noexcept( mp11::mp_all...>::value ) { - mp_with_index( r.index(), L7{ this, r } ); + mp11::mp_with_index( r.index(), L7{ this, r } ); } // subset (extension) private: - template::type> static constexpr variant _subset_impl( mp_size_t, V && v ) + template::type> static constexpr variant _subset_impl( mp11::mp_size_t, V && v ) { return variant( in_place_index_t(), std::forward(v) ); } - template static variant _subset_impl( mp_size_t, V && /*v*/ ) + template static variant _subset_impl( mp11::mp_size_t, V && /*v*/ ) { throw bad_variant_access(); } @@ -1320,7 +1318,7 @@ private: template variant operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; return this_->_subset_impl( J{}, this_->_get_impl( i ) ); } }; @@ -1328,10 +1326,10 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > BOOST_CXX14_CONSTEXPR variant subset() & { - return mp_with_index( index(), L8{ this } ); + return mp11::mp_with_index( index(), L8{ this } ); } private: @@ -1342,7 +1340,7 @@ private: template variant operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; return this_->_subset_impl( J{}, this_->_get_impl( i ) ); } }; @@ -1350,10 +1348,10 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > constexpr variant subset() const& { - return mp_with_index( index(), L9{ this } ); + return mp11::mp_with_index( index(), L9{ this } ); } private: @@ -1364,7 +1362,7 @@ private: template variant operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; return this_->_subset_impl( J{}, std::move( this_->_get_impl( i ) ) ); } }; @@ -1372,10 +1370,10 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > BOOST_CXX14_CONSTEXPR variant subset() && { - return mp_with_index( index(), L10{ this } ); + return mp11::mp_with_index( index(), L10{ this } ); } #if !BOOST_WORKAROUND(BOOST_GCC, < 40900) @@ -1390,7 +1388,7 @@ private: template variant operator()( I i ) const { - using J = mp_find, mp_at, I>>; + using J = mp11::mp_find, mp11::mp_at, I>>; return this_->_subset_impl( J{}, std::move( this_->_get_impl( i ) ) ); } }; @@ -1398,10 +1396,10 @@ private: public: template..., mp_contains, U>...>, void> > + class E2 = mp11::mp_if..., mp11::mp_contains, U>...>, void> > constexpr variant subset() const&& { - return mp_with_index( index(), L11{ this } ); + return mp11::mp_with_index( index(), L11{ this } ); } #endif @@ -1427,7 +1425,7 @@ template struct eq_L template constexpr bool operator==( variant const & v, variant const & w ) { - return v.index() == w.index() && mp_with_index( v.index(), detail::eq_L{ v, w } ); + return v.index() == w.index() && mp11::mp_with_index( v.index(), detail::eq_L{ v, w } ); } namespace detail @@ -1448,7 +1446,7 @@ template struct ne_L template constexpr bool operator!=( variant const & v, variant const & w ) { - return v.index() != w.index() || mp_with_index( v.index(), detail::ne_L{ v, w } ); + return v.index() != w.index() || mp11::mp_with_index( v.index(), detail::ne_L{ v, w } ); } namespace detail @@ -1469,7 +1467,7 @@ template struct lt_L template constexpr bool operator<( variant const & v, variant const & w ) { - return v.index() < w.index() || ( v.index() == w.index() && mp_with_index( v.index(), detail::lt_L{ v, w } ) ); + return v.index() < w.index() || ( v.index() == w.index() && mp11::mp_with_index( v.index(), detail::lt_L{ v, w } ) ); } template constexpr bool operator>( variant const & v, variant const & w ) @@ -1495,7 +1493,7 @@ template struct le_L template constexpr bool operator<=( variant const & v, variant const & w ) { - return v.index() < w.index() || ( v.index() == w.index() && mp_with_index( v.index(), detail::le_L{ v, w } ) ); + return v.index() < w.index() || ( v.index() == w.index() && mp11::mp_with_index( v.index(), detail::le_L{ v, w } ) ); } template constexpr bool operator>=( variant const & v, variant const & w ) @@ -1512,11 +1510,11 @@ template struct Qret template using fn = decltype( std::declval()( std::declval()... ) ); }; -template using front_if_same = mp_if, mp_front>; +template using front_if_same = mp11::mp_if, mp11::mp_front>; template using var_size = variant_size::type>; -template::type>> using apply_cv_ref_ = mp_if, T&, T>; +template::type>> using apply_cv_ref_ = mp11::mp_if, T&, T>; #if BOOST_WORKAROUND( BOOST_MSVC, < 1920 ) @@ -1524,20 +1522,20 @@ template struct apply_cv_ref_impl { template using _f = apply_cv_ref_; - using L = mp_iota>; + using L = mp11::mp_iota>; - using type = mp_transform<_f, L>; + using type = mp11::mp_transform<_f, L>; }; template using apply_cv_ref = typename apply_cv_ref_impl::type; #else -template using apply_cv_ref = mp_transform_q, mp_iota>>; +template using apply_cv_ref = mp11::mp_transform_q, mp11::mp_iota>>; #endif -template using Vret = front_if_same, apply_cv_ref...>>; +template using Vret = front_if_same, apply_cv_ref...>>; } // namespace detail @@ -1564,7 +1562,7 @@ template struct visit_L1 template constexpr auto visit( F&& f, V1&& v1 ) -> variant2::detail::Vret { - return mp_with_index>( v1.index(), detail::visit_L1{ std::forward(f), std::forward(v1) } ); + return mp11::mp_with_index>( v1.index(), detail::visit_L1{ std::forward(f), std::forward(v1) } ); } #if defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) || BOOST_WORKAROUND( BOOST_MSVC, < 1920 ) @@ -1606,7 +1604,7 @@ template struct visit_L2 template constexpr auto visit( F&& f, V1&& v1, V2&& v2 ) -> variant2::detail::Vret { - return mp_with_index>( v1.index(), detail::visit_L2{ std::forward(f), std::forward(v1), std::forward(v2) } ); + return mp11::mp_with_index>( v1.index(), detail::visit_L2{ std::forward(f), std::forward(v1), std::forward(v2) } ); } namespace detail @@ -1631,7 +1629,7 @@ template struct visit_L3 template constexpr auto visit( F&& f, V1&& v1, V2&& v2, V3&& v3 ) -> variant2::detail::Vret { - return mp_with_index>( v1.index(), detail::visit_L3{ std::forward(f), std::forward(v1), std::forward(v2), std::forward(v3) } ); + return mp11::mp_with_index>( v1.index(), detail::visit_L3{ std::forward(f), std::forward(v1), std::forward(v2), std::forward(v3) } ); } namespace detail @@ -1657,14 +1655,14 @@ template struct visit_L4 template constexpr auto visit( F&& f, V1&& v1, V2&& v2, V3&& v3, V4&& v4 ) -> variant2::detail::Vret { - return mp_with_index>( v1.index(), detail::visit_L4{ std::forward(f), std::forward(v1), std::forward(v2), std::forward(v3), std::forward(v4) } ); + return mp11::mp_with_index>( v1.index(), detail::visit_L4{ std::forward(f), std::forward(v1), std::forward(v2), std::forward(v3), std::forward(v4) } ); } #else template constexpr auto visit( F&& f, V1&& v1, V2&& v2, V&&... v ) -> variant2::detail::Vret { - return mp_with_index>( v1.index(), [&]( auto I ){ + return mp11::mp_with_index>( v1.index(), [&]( auto I ){ auto f2 = [&]( auto&&... a ){ return std::forward(f)( get( std::forward(v1) ), std::forward(a)... ); }; return visit( f2, std::forward(v2), std::forward(v)... ); @@ -1676,7 +1674,7 @@ template constexpr auto visit( F&& f, V // specialized algorithms template..., variant2::detail::is_swappable...>::value>::type> + class E = typename std::enable_if..., variant2::detail::is_swappable...>::value>::type> void swap( variant & v, variant & w ) noexcept( noexcept(v.swap(w)) ) {