diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 260411c..b20bdf8 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -45,7 +45,33 @@ public: } }; -// +// monostate + +struct monostate +{ +}; + +constexpr bool operator<(monostate, monostate) noexcept { return false; } +constexpr bool operator>(monostate, monostate) noexcept { return false; } +constexpr bool operator<=(monostate, monostate) noexcept { return true; } +constexpr bool operator>=(monostate, monostate) noexcept { return true; } +constexpr bool operator==(monostate, monostate) noexcept { return true; } +constexpr bool operator!=(monostate, monostate) noexcept { return false; } + +// valueless + +struct valueless +{ +}; + +constexpr bool operator<(valueless, valueless) noexcept { return false; } +constexpr bool operator>(valueless, valueless) noexcept { return false; } +constexpr bool operator<=(valueless, valueless) noexcept { return true; } +constexpr bool operator>=(valueless, valueless) noexcept { return true; } +constexpr bool operator==(valueless, valueless) noexcept { return true; } +constexpr bool operator!=(valueless, valueless) noexcept { return false; } + +// variant forward declaration template class variant; @@ -434,7 +460,7 @@ template using resolve_overload_index = mp_find struct variant_base_impl; // trivially destructible, single buffered -template using variant_base = variant_base_impl...>::value, mp_any...>, std::is_nothrow_default_constructible...>::value, T...>; +template using variant_base = variant_base_impl...>::value, mp_any...>, std::is_same...>::value, T...>; struct none {}; @@ -491,9 +517,9 @@ template struct variant_base_impl template void emplace_impl( mp_false, mp_false, A&&... a ) { - std::size_t const K = mp_find_if, std::is_nothrow_constructible>::value; + std::size_t const K = mp_find, valueless>::value; - if( K < sizeof...(T) ) // have nothrow destructible + if( K < sizeof...(T) ) // have valueless { try { @@ -644,7 +670,7 @@ template struct variant_base_impl { size_t const J = I+1; - std::size_t const K = mp_find_if, std::is_nothrow_constructible>::value; + std::size_t const K = mp_find, valueless>::value; using U = mp_at_c, I>; @@ -655,7 +681,7 @@ template struct variant_base_impl st1_.emplace( mp_size_t(), std::forward(a)... ); ix_ = J; } - else if( K < sizeof...(T) ) // have nothrow destructible + else if( K < sizeof...(T) ) // have valueless { _destroy();