updated move assignments and swap operations to "N4258: Cleaning-up noexcept in the Library, Rev 3" with some customizations.

This commit is contained in:
Ion Gaztañaga
2015-01-19 00:18:44 +01:00
parent 18ad354dcf
commit dbafd61d4d
13 changed files with 94 additions and 34 deletions

View File

@@ -733,7 +733,8 @@ class deque : protected deque_base<Allocator>
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
deque& operator= (BOOST_RV_REF(deque) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
BOOST_ASSERT(this != &x);
allocator_type &this_alloc = this->alloc();
@@ -1622,6 +1623,8 @@ class deque : protected deque_base<Allocator>
//!
//! <b>Complexity</b>: Constant.
void swap(deque &x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value)
{
this->swap_members(x);
container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;

View File

@@ -100,6 +100,7 @@ class flat_tree
{
typedef boost::container::vector<Value, Allocator> vector_t;
typedef Allocator allocator_t;
typedef allocator_traits<Allocator> allocator_traits_type;
public:
typedef flat_tree_value_compare<Compare, Value, KeyOfValue> value_compare;
@@ -264,6 +265,8 @@ class flat_tree
{ m_data = x.m_data; return *this; }
flat_tree& operator=(BOOST_RV_REF(flat_tree) x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ m_data = boost::move(x.m_data); return *this; }
public:
@@ -329,6 +332,8 @@ class flat_tree
{ return this->m_data.m_vect.max_size(); }
void swap(flat_tree& other)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
{ this->m_data.swap(other.m_data); }
public:

View File

@@ -481,6 +481,8 @@ class tree
typedef tree < Key, T, KeyOfValue
, Compare, Allocator, Options> ThisType;
typedef typename AllocHolder::NodeAlloc NodeAlloc;
typedef boost::container::
allocator_traits<NodeAlloc> allocator_traits_type;
typedef typename AllocHolder::ValAlloc ValAlloc;
typedef typename AllocHolder::Node Node;
typedef typename Icont::iterator iiterator;
@@ -696,6 +698,8 @@ class tree
}
tree& operator=(BOOST_RV_REF(tree) x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{
BOOST_ASSERT(this != &x);
NodeAlloc &this_alloc = this->node_alloc();
@@ -820,6 +824,8 @@ class tree
{ return AllocHolder::max_size(); }
void swap(ThisType& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
{ AllocHolder::swap(x); }
public:

View File

@@ -50,6 +50,7 @@ using ::boost::move_detail::is_nothrow_copy_constructible;
using ::boost::move_detail::is_nothrow_move_constructible;
using ::boost::move_detail::is_nothrow_copy_assignable;
using ::boost::move_detail::is_nothrow_move_assignable;
using ::boost::move_detail::is_nothrow_swappable;
using ::boost::move_detail::alignment_of;
using ::boost::move_detail::aligned_storage;
using ::boost::move_detail::nat;

View File

@@ -330,7 +330,8 @@ class flat_map
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
flat_map& operator=(BOOST_RV_REF(flat_map) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ m_flat_tree = boost::move(x.m_flat_tree); return *this; }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -877,6 +878,8 @@ class flat_map
//!
//! <b>Complexity</b>: Constant.
void swap(flat_map& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
{ m_flat_tree.swap(x.m_flat_tree); }
//! <b>Effects</b>: erase(a.begin(),a.end()).
@@ -1314,7 +1317,8 @@ class flat_multimap
//!
//! <b>Complexity</b>: Constant.
flat_multimap& operator=(BOOST_RV_REF(flat_multimap) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ m_flat_tree = boost::move(x.m_flat_tree); return *this; }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -1780,6 +1784,8 @@ class flat_multimap
//!
//! <b>Complexity</b>: Constant.
void swap(flat_multimap& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
{ m_flat_tree.swap(x.m_flat_tree); }
//! <b>Effects</b>: erase(a.begin(),a.end()).

View File

@@ -232,7 +232,8 @@ class flat_set
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
flat_set& operator=(BOOST_RV_REF(flat_set) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<flat_set&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -619,7 +620,9 @@ class flat_set
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
void swap(flat_set& x);
void swap(flat_set& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! <b>Effects</b>: erase(a.begin(),a.end()).
//!
@@ -956,7 +959,8 @@ class flat_multiset
//! @copydoc ::boost::container::flat_set::operator=(flat_set &&)
flat_multiset& operator=(BOOST_RV_REF(flat_multiset) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<flat_multiset&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -1198,7 +1202,9 @@ class flat_multiset
iterator erase(const_iterator first, const_iterator last);
//! @copydoc ::boost::container::flat_set::swap
void swap(flat_multiset& x);
void swap(flat_multiset& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! @copydoc ::boost::container::flat_set::clear
void clear() BOOST_CONTAINER_NOEXCEPT;

View File

@@ -339,7 +339,8 @@ class list
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
list& operator=(BOOST_RV_REF(list) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
BOOST_ASSERT(this != &x);
NodeAlloc &this_alloc = this->node_alloc();
@@ -931,6 +932,8 @@ class list
//!
//! <b>Complexity</b>: Constant.
void swap(list& x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value)
{ AllocHolder::swap(x); }
//! <b>Effects</b>: Erases all the elements of the list.

View File

@@ -272,7 +272,9 @@ class map
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
map& operator=(BOOST_RV_REF(map) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<map&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -680,7 +682,9 @@ class map
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
void swap(map& x);
void swap(map& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
//! <b>Effects</b>: erase(a.begin(),a.end()).
//!
@@ -894,6 +898,8 @@ class multimap
> value_compare_impl;
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
public:
//////////////////////////////////////////////
//
@@ -1065,6 +1071,8 @@ class multimap
//!
//! <b>Complexity</b>: Constant.
multimap& operator=(BOOST_RV_REF(multimap) x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<multimap&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -1281,7 +1289,9 @@ class multimap
iterator erase(const_iterator first, const_iterator last);
//! @copydoc ::boost::container::set::swap
void swap(flat_multiset& x);
void swap(multiset& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! @copydoc ::boost::container::set::clear
void clear() BOOST_CONTAINER_NOEXCEPT;

View File

@@ -224,7 +224,8 @@ class set
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
set& operator=(BOOST_RV_REF(set) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<set&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -522,7 +523,9 @@ class set
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
void swap(set& x);
void swap(set& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! <b>Effects</b>: erase(a.begin(),a.end()).
//!
@@ -835,6 +838,8 @@ class multiset
//! @copydoc ::boost::container::set::operator=(set &&)
multiset& operator=(BOOST_RV_REF(multiset) x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
{ return static_cast<multiset&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
@@ -1013,7 +1018,9 @@ class multiset
iterator erase(const_iterator first, const_iterator last);
//! @copydoc ::boost::container::set::swap
void swap(flat_multiset& x);
void swap(multiset& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! @copydoc ::boost::container::set::clear
void clear() BOOST_CONTAINER_NOEXCEPT;

View File

@@ -358,7 +358,8 @@ class slist
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
slist& operator= (BOOST_RV_REF(slist) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
BOOST_ASSERT(this != &x);
NodeAlloc &this_alloc = this->node_alloc();
@@ -916,6 +917,8 @@ class slist
//!
//! <b>Complexity</b>: Linear to the number of elements on *this and x.
void swap(slist& x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value)
{ AllocHolder::swap(x); }
//! <b>Effects</b>: Erases all the elements of the list.

View File

@@ -751,7 +751,8 @@ class stable_vector
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
stable_vector& operator=(BOOST_RV_REF(stable_vector) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
//for move constructor, no aliasing (&x != this) is assummed.
BOOST_ASSERT(this != &x);
@@ -1598,6 +1599,8 @@ class stable_vector
//!
//! <b>Complexity</b>: Constant.
void swap(stable_vector & x)
BOOST_CONTAINER_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value)
{
STABLE_VECTOR_CHECK_INVARIANT;
container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;

View File

@@ -751,7 +751,8 @@ class basic_string
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
basic_string& operator=(BOOST_RV_REF(basic_string) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
//for move constructor, no aliasing (&x != this) is assummed.
BOOST_ASSERT(this != &x);
@@ -1892,6 +1893,8 @@ class basic_string
//!
//! <b>Throws</b>: Nothing
void swap(basic_string& x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value)
{
this->base_t::swap_data(x);
container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;

View File

@@ -896,7 +896,8 @@ class vector
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
vector& operator=(BOOST_RV_REF(vector) x)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
this->priv_move_assign(boost::move(x));
return *this;
@@ -1784,7 +1785,10 @@ class vector
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
void swap(vector& x) BOOST_CONTAINER_NOEXCEPT_IF((!container_detail::is_version<Allocator, 0>::value))
void swap(vector& x)
BOOST_CONTAINER_NOEXCEPT_IF( ((allocator_traits_type::propagate_on_container_swap::value
|| allocator_traits_type::is_always_equal::value) &&
!container_detail::is_version<Allocator, 0>::value))
{
//Just swap internals in case of !version_0. Otherwise, deep swap
this->m_holder.swap(x.m_holder);