Index: include/variant =================================================================== --- include/variant +++ include/variant @@ -1097,11 +1097,40 @@ template struct __overload<_Tp, _Types...> : __overload<_Types...> { using __overload<_Types...>::operator(); - __identity<_Tp> operator()(_Tp) const; + + template + auto operator()(_Tp, _Up&& __t) const + -> decltype(_Tp{__t}, __identity<_Tp>()); +}; + +template +struct __overload_bool : _Base { + using _Base::operator(); + + template > + auto operator()(bool, _Up&&, int _Ap::* = 0) const -> __identity<_Tp>; + + template > + auto operator()(bool, _Up&&) const + -> enable_if_t, __identity<_Tp>>; }; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool const> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool volatile> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool const volatile> {}; + template -using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; +using __best_match_t = + typename invoke_result_t<__overload<_Types...>, _Tp, _Tp>::type; } // __variant_detail Index: test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp =================================================================== --- test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp +++ test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "test_macros.h" #include "variant_test_helpers.hpp" @@ -128,7 +129,7 @@ void test_T_assignment_sfinae() { { - using V = std::variant; + using V = std::variant; static_assert(!std::is_assignable::value, "ambiguous"); } { @@ -139,6 +140,15 @@ using V = std::variant; static_assert(!std::is_assignable::value, "no matching operator="); } + { + using V = std::variant; + static_assert(!std::is_assignable::value, "no matching operator="); + } + { + using V = std::variant, bool>; + static_assert(!std::is_assignable>::value, + "no explicit bool in operator="); + } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { using V = std::variant; @@ -167,6 +177,44 @@ assert(v.index() == 1); assert(std::get<1>(v) == 43); } + { + std::variant v; + v = 42; + assert(v.index() == 1); + assert(std::get<1>(v) == 42); + v = 43u; + assert(v.index() == 0); + assert(std::get<0>(v) == 43); + } + { + std::variant v = true; + v = std::false_type(); + assert(v.index() == 1); + assert(std::get<1>(v) == false); + v = "bar"; + assert(v.index() == 0); + assert(std::get<0>(v) == "bar"); + } + { + std::variant> v; + v = nullptr; + assert(v.index() == 1); + assert(std::get<1>(v) == nullptr); + v = std::true_type(); + assert(v.index() == 0); + assert(std::get<0>(v)); + } + { + std::variant v = 42; + assert(v.index() == 1); + assert(std::get<1>(v) == 42); + v = std::false_type(); + assert(v.index() == 0); + assert(!std::get<0>(v)); + v = true; + assert(v.index() == 0); + assert(std::get<0>(v)); + } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { using V = std::variant; Index: test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp =================================================================== --- test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp +++ test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "test_convertible.hpp" #include "test_macros.h" @@ -53,7 +54,7 @@ void test_T_ctor_sfinae() { { - using V = std::variant; + using V = std::variant; static_assert(!std::is_constructible::value, "ambiguous"); } { @@ -66,6 +67,16 @@ "no matching constructor"); } { + using V = std::variant; + static_assert(!std::is_constructible::value, + "no matching constructor"); + } + { + using V = std::variant, bool>; + static_assert(!std::is_constructible>::value, + "no explicit bool in constructor"); + } + { using V = std::variant; static_assert( !std::is_constructible>::value, @@ -99,6 +110,26 @@ static_assert(v.index() == 1, ""); static_assert(std::get<1>(v) == 42, ""); } + { + constexpr std::variant v(42); + static_assert(v.index() == 1, ""); + static_assert(std::get<1>(v) == 42, ""); + } + { + std::variant v = "foo"; + assert(v.index() == 0); + assert(std::get<0>(v) == "foo"); + } + { + std::variant> v = nullptr; + assert(v.index() == 1); + assert(std::get<1>(v) == nullptr); + } + { + std::variant v = true; + assert(v.index() == 0); + assert(std::get<0>(v)); + } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { using V = std::variant;