From 7f7c74522b321458a2348c9ba67bc3eb7632e834 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 12 May 2019 01:46:55 +0300 Subject: [PATCH] Strong guarantee on assignment --- include/boost/variant2/variant.hpp | 35 +++++------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 7834ef7..4bf0577 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -1168,14 +1168,7 @@ private: template void operator()( I i ) const { - if( this_->index() == i ) - { - this_->_get_impl( i ) = r._get_impl( i ); - } - else - { - this_->variant_base::template emplace( r._get_impl( i ) ); - } + this_->variant_base::template emplace( r._get_impl( i ) ); } }; @@ -1186,7 +1179,7 @@ public: class E3 = mp11::mp_if..., std::is_copy_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant const & r ) - noexcept( mp11::mp_all..., std::is_nothrow_copy_assignable...>::value ) + noexcept( mp11::mp_all...>::value ) { mp11::mp_with_index( r.index(), L3{ this, r } ); return *this; @@ -1210,14 +1203,7 @@ private: template void operator()( I i ) const { - if( this_->index() == i ) - { - this_->_get_impl( i ) = std::move( r._get_impl( i ) ); - } - else - { - this_->variant_base::template emplace( std::move( r._get_impl( i ) ) ); - } + this_->variant_base::template emplace( std::move( r._get_impl( i ) ) ); } }; @@ -1228,7 +1214,7 @@ public: class E3 = mp11::mp_if..., std::is_move_assignable...>, E1> > variant& operator=( variant && r ) - noexcept( mp11::mp_all..., std::is_nothrow_move_assignable...>::value ) + noexcept( mp11::mp_all...>::value ) { mp11::mp_with_index( r.index(), L4{ this, r } ); return *this; @@ -1240,19 +1226,10 @@ public: class E2 = typename std::enable_if::value && std::is_constructible::value>::type > BOOST_CXX14_CONSTEXPR variant& operator=( U&& u ) - noexcept( std::is_nothrow_assignable::value && std::is_nothrow_constructible::value ) + noexcept( std::is_nothrow_constructible::value ) { std::size_t const I = detail::resolve_overload_index::value; - - if( index() == I ) - { - _get_impl( mp11::mp_size_t() ) = std::forward(u); - } - else - { - this->template emplace( std::forward(u) ); - } - + this->template emplace( std::forward(u) ); return *this; }