Statically handle 'is_unique' in assignments

This commit is contained in:
Daniel James
2017-05-06 04:58:57 +01:00
parent 6e074d7165
commit b6c6bfbe7f
3 changed files with 53 additions and 51 deletions

View File

@ -3098,7 +3098,8 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Assignment // Assignment
void assign(table const& x, bool is_unique) template <typename UniqueType>
void assign(table const& x, UniqueType is_unique)
{ {
if (this != boost::addressof(x)) { if (this != boost::addressof(x)) {
assign(x, is_unique, assign(x, is_unique,
@ -3108,7 +3109,8 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void assign(table const& x, bool is_unique, false_type) template <typename UniqueType>
void assign(table const& x, UniqueType is_unique, false_type)
{ {
// Strong exception safety. // Strong exception safety.
set_hash_functions new_func_this(*this, x); set_hash_functions new_func_this(*this, x);
@ -3123,14 +3125,11 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
new_func_this.commit(); new_func_this.commit();
if (is_unique) { assign_buckets(x, is_unique);
assign_buckets_unique(x);
} else {
assign_buckets_equiv(x);
}
} }
void assign(table const& x, bool is_unique, true_type) template <typename UniqueType>
void assign(table const& x, UniqueType is_unique, true_type)
{ {
if (node_alloc() == x.node_alloc()) { if (node_alloc() == x.node_alloc()) {
allocators_.assign(x.allocators_); allocators_.assign(x.allocators_);
@ -3150,16 +3149,13 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
// Finally copy the elements. // Finally copy the elements.
if (x.size_) { if (x.size_) {
if (is_unique) { copy_buckets(x, is_unique);
copy_buckets_unique(x);
} else {
copy_buckets_equiv(x);
}
} }
} }
} }
void move_assign(table& x, bool is_unique) template <typename UniqueType>
void move_assign(table& x, UniqueType is_unique)
{ {
if (this != boost::addressof(x)) { if (this != boost::addressof(x)) {
move_assign( move_assign(
@ -3170,7 +3166,8 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void move_assign(table& x, bool /* is_unique */, true_type) template <typename UniqueType>
void move_assign(table& x, UniqueType, true_type)
{ {
delete_buckets(); delete_buckets();
set_hash_functions new_func_this(*this, x); set_hash_functions new_func_this(*this, x);
@ -3181,7 +3178,8 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
new_func_this.commit(); new_func_this.commit();
} }
void move_assign(table& x, bool is_unique, false_type) template <typename UniqueType>
void move_assign(table& x, UniqueType is_unique, false_type)
{ {
if (node_alloc() == x.node_alloc()) { if (node_alloc() == x.node_alloc()) {
delete_buckets(); delete_buckets();
@ -3203,11 +3201,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
new_func_this.commit(); new_func_this.commit();
if (is_unique) { move_assign_buckets(x, is_unique);
move_assign_buckets_unique(x);
} else {
move_assign_buckets_equiv(x);
}
} }
} }
@ -3724,7 +3718,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// fill_buckets_unique // fill_buckets_unique
void copy_buckets_unique(table const& src) void copy_buckets(table const& src, true_type)
{ {
this->create_buckets(this->bucket_count_); this->create_buckets(this->bucket_count_);
@ -3751,7 +3745,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void assign_buckets_unique(table const& src) void assign_buckets(table const& src, true_type)
{ {
node_holder<node_allocator> holder(*this); node_holder<node_allocator> holder(*this);
for (node_pointer n = src.begin(); n; n = next_node(n)) { for (node_pointer n = src.begin(); n; n = next_node(n)) {
@ -3760,7 +3754,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void move_assign_buckets_unique(table& src) void move_assign_buckets(table& src, true_type)
{ {
node_holder<node_allocator> holder(*this); node_holder<node_allocator> holder(*this);
for (node_pointer n = src.begin(); n; n = next_node(n)) { for (node_pointer n = src.begin(); n; n = next_node(n)) {
@ -4121,7 +4115,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// fill_buckets // fill_buckets
void copy_buckets_equiv(table const& src) void copy_buckets(table const& src, false_type)
{ {
this->create_buckets(this->bucket_count_); this->create_buckets(this->bucket_count_);
@ -4161,7 +4155,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void assign_buckets_equiv(table const& src) void assign_buckets(table const& src, false_type)
{ {
node_holder<node_allocator> holder(*this); node_holder<node_allocator> holder(*this);
for (node_pointer n = src.begin(); n;) { for (node_pointer n = src.begin(); n;) {
@ -4175,7 +4169,7 @@ struct table : boost::unordered::detail::functions<typename Types::hasher,
} }
} }
void move_assign_buckets_equiv(table& src) void move_assign_buckets(table& src, false_type)
{ {
node_holder<node_allocator> holder(*this); node_holder<node_allocator> holder(*this);
for (node_pointer n = src.begin(); n;) { for (node_pointer n = src.begin(); n;) {

View File

@ -146,7 +146,7 @@ template <class K, class T, class H, class P, class A> class unordered_map
#if defined(BOOST_UNORDERED_USE_MOVE) #if defined(BOOST_UNORDERED_USE_MOVE)
unordered_map& operator=(BOOST_COPY_ASSIGN_REF(unordered_map) x) unordered_map& operator=(BOOST_COPY_ASSIGN_REF(unordered_map) x)
{ {
table_.assign(x.table_, true); table_.assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
@ -156,13 +156,13 @@ template <class K, class T, class H, class P, class A> class unordered_map
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, true); table_.move_assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
#else #else
unordered_map& operator=(unordered_map const& x) unordered_map& operator=(unordered_map const& x)
{ {
table_.assign(x.table_, true); table_.assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
@ -173,7 +173,7 @@ template <class K, class T, class H, class P, class A> class unordered_map
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, true); table_.move_assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
#endif #endif
@ -948,7 +948,7 @@ template <class K, class T, class H, class P, class A> class unordered_multimap
#if defined(BOOST_UNORDERED_USE_MOVE) #if defined(BOOST_UNORDERED_USE_MOVE)
unordered_multimap& operator=(BOOST_COPY_ASSIGN_REF(unordered_multimap) x) unordered_multimap& operator=(BOOST_COPY_ASSIGN_REF(unordered_multimap) x)
{ {
table_.assign(x.table_, false); table_.assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
@ -958,13 +958,13 @@ template <class K, class T, class H, class P, class A> class unordered_multimap
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, false); table_.move_assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
#else #else
unordered_multimap& operator=(unordered_multimap const& x) unordered_multimap& operator=(unordered_multimap const& x)
{ {
table_.assign(x.table_, false); table_.assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
@ -975,7 +975,7 @@ template <class K, class T, class H, class P, class A> class unordered_multimap
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, false); table_.move_assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
#endif #endif
@ -1399,7 +1399,8 @@ unordered_map<K, T, H, P, A>::unordered_map(unordered_map const& other)
select_on_container_copy_construction(other.get_allocator())) select_on_container_copy_construction(other.get_allocator()))
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_unique(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::true_type());
} }
} }
@ -1416,7 +1417,8 @@ unordered_map<K, T, H, P, A>::unordered_map(
: table_(other.table_, a) : table_(other.table_, a)
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_unique(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::true_type());
} }
} }
@ -1877,7 +1879,8 @@ unordered_multimap<K, T, H, P, A>::unordered_multimap(
select_on_container_copy_construction(other.get_allocator())) select_on_container_copy_construction(other.get_allocator()))
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_equiv(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::false_type());
} }
} }
@ -1894,7 +1897,8 @@ unordered_multimap<K, T, H, P, A>::unordered_multimap(
: table_(other.table_, a) : table_(other.table_, a)
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_equiv(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::false_type());
} }
} }

View File

@ -144,7 +144,7 @@ template <class T, class H, class P, class A> class unordered_set
#if defined(BOOST_UNORDERED_USE_MOVE) #if defined(BOOST_UNORDERED_USE_MOVE)
unordered_set& operator=(BOOST_COPY_ASSIGN_REF(unordered_set) x) unordered_set& operator=(BOOST_COPY_ASSIGN_REF(unordered_set) x)
{ {
table_.assign(x.table_, true); table_.assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
@ -154,13 +154,13 @@ template <class T, class H, class P, class A> class unordered_set
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, true); table_.move_assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
#else #else
unordered_set& operator=(unordered_set const& x) unordered_set& operator=(unordered_set const& x)
{ {
table_.assign(x.table_, true); table_.assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
@ -171,7 +171,7 @@ template <class T, class H, class P, class A> class unordered_set
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, true); table_.move_assign(x.table_, boost::unordered::detail::true_type());
return *this; return *this;
} }
#endif #endif
@ -654,7 +654,7 @@ template <class T, class H, class P, class A> class unordered_multiset
#if defined(BOOST_UNORDERED_USE_MOVE) #if defined(BOOST_UNORDERED_USE_MOVE)
unordered_multiset& operator=(BOOST_COPY_ASSIGN_REF(unordered_multiset) x) unordered_multiset& operator=(BOOST_COPY_ASSIGN_REF(unordered_multiset) x)
{ {
table_.assign(x.table_, false); table_.assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
@ -664,13 +664,13 @@ template <class T, class H, class P, class A> class unordered_multiset
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, false); table_.move_assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
#else #else
unordered_multiset& operator=(unordered_multiset const& x) unordered_multiset& operator=(unordered_multiset const& x)
{ {
table_.assign(x.table_, false); table_.assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
@ -681,7 +681,7 @@ template <class T, class H, class P, class A> class unordered_multiset
// is_nothrow_move_assignable_v<H> && // is_nothrow_move_assignable_v<H> &&
// is_nothrow_move_assignable_v<P>) // is_nothrow_move_assignable_v<P>)
{ {
table_.move_assign(x.table_, false); table_.move_assign(x.table_, boost::unordered::detail::false_type());
return *this; return *this;
} }
#endif #endif
@ -1078,7 +1078,8 @@ unordered_set<T, H, P, A>::unordered_set(unordered_set const& other)
select_on_container_copy_construction(other.get_allocator())) select_on_container_copy_construction(other.get_allocator()))
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_unique(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::true_type());
} }
} }
@ -1095,7 +1096,8 @@ unordered_set<T, H, P, A>::unordered_set(
: table_(other.table_, a) : table_(other.table_, a)
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_unique(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::true_type());
} }
} }
@ -1472,7 +1474,8 @@ unordered_multiset<T, H, P, A>::unordered_multiset(
select_on_container_copy_construction(other.get_allocator())) select_on_container_copy_construction(other.get_allocator()))
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_equiv(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::false_type());
} }
} }
@ -1489,7 +1492,8 @@ unordered_multiset<T, H, P, A>::unordered_multiset(
: table_(other.table_, a) : table_(other.table_, a)
{ {
if (other.table_.size_) { if (other.table_.size_) {
table_.copy_buckets_equiv(other.table_); table_.copy_buckets(
other.table_, boost::unordered::detail::false_type());
} }
} }