diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 5b3fc76..145df70 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -122,7 +122,7 @@ template constexpr variant_alternative_t() ); #endif @@ -132,9 +132,16 @@ template constexpr variant_alternative_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) @@ -157,9 +164,16 @@ template constexpr variant_alternative_t() ) ); + +#else + + if( v.index() != I ) throw bad_variant_access(); return std::move( v._get_impl( mp_size_t() ) ); + +#endif } // get @@ -186,9 +200,16 @@ 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" ); constexpr auto I = mp_find, U>::value; - if( v.index() != I ) throw bad_variant_access(); +#if BOOST_WORKAROUND( BOOST_GCC, < 60000 ) + 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 U const& get(variant const& v) @@ -213,9 +234,16 @@ 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" ); constexpr auto I = mp_find, U>::value; - if( v.index() != I ) throw bad_variant_access(); +#if BOOST_WORKAROUND( BOOST_GCC, < 60000 ) + 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_if