diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 01655cb..3cd3275 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -140,7 +140,17 @@ template constexpr variant_alternative_t constexpr variant_alternative_t>&& get(variant&& v) { static_assert( I < sizeof...(T), "Index out of bounds" ); + +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) + return (void)( v.index() != I? throw bad_variant_access(): 0 ), std::move( v._get_impl( mp_size_t() ) ); + +#else + + if( v.index() != I ) throw bad_variant_access(); + return std::move( v._get_impl( mp_size_t() ) ); + +#endif } template constexpr variant_alternative_t> const& get(variant const& v) @@ -152,7 +162,17 @@ template constexpr variant_alternative_t constexpr variant_alternative_t> const&& get(variant const&& v) { static_assert( I < sizeof...(T), "Index out of bounds" ); + +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) + return (void)( v.index() != I? throw bad_variant_access(): 0 ), std::move( v._get_impl( mp_size_t() ) ); + +#else + + if( v.index() != I ) throw bad_variant_access(); + return std::move( v._get_impl( mp_size_t() ) ); + +#endif } // get (type) @@ -172,7 +192,16 @@ template constexpr U&& get(variant&& v) using I = mp_find, U>; +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) + return (void)( v.index() != I::value? throw bad_variant_access(): 0 ), std::move( v._get_impl( I() ) ); + +#else + + if( v.index() != I::value ) throw bad_variant_access(); + return std::move( v._get_impl( I() ) ); + +#endif } template constexpr U const& get(variant const& v) @@ -190,7 +219,16 @@ template constexpr U const&& get(variant const&& v) using I = mp_find, U>; +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920) + return (void)( v.index() != I::value? throw bad_variant_access(): 0 ), std::move( v._get_impl( I() ) ); + +#else + + if( v.index() != I::value ) throw bad_variant_access(); + return std::move( v._get_impl( I() ) ); + +#endif } // get_if