From 9847a9f6262c289ac70ca62622bd7efbc2b752a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 24 Nov 2012 21:05:58 +0000 Subject: [PATCH] * Fixed GCC -Wshadow warnings. * Added missing `explicit` keyword in several intrusive container constructors. * Replaced deprecated BOOST_NO_XXXX with newer BOOST_NO_CXX11_XXX macros. [SVN r81516] --- include/boost/intrusive/avl_set.hpp | 8 +- include/boost/intrusive/avltree.hpp | 16 +- .../intrusive/circular_list_algorithms.hpp | 2 +- .../intrusive/detail/tree_algorithms.hpp | 2 +- include/boost/intrusive/hashtable.hpp | 208 +++++------ include/boost/intrusive/list.hpp | 26 +- include/boost/intrusive/rbtree.hpp | 4 +- include/boost/intrusive/set.hpp | 8 +- include/boost/intrusive/sg_set.hpp | 8 +- include/boost/intrusive/sgtree.hpp | 12 +- include/boost/intrusive/slist.hpp | 338 +++++++++++------- include/boost/intrusive/splay_set.hpp | 8 +- include/boost/intrusive/splaytree.hpp | 8 +- include/boost/intrusive/treap.hpp | 20 +- include/boost/intrusive/treap_set.hpp | 12 +- include/boost/intrusive/unordered_set.hpp | 16 +- 16 files changed, 383 insertions(+), 313 deletions(-) diff --git a/include/boost/intrusive/avl_set.hpp b/include/boost/intrusive/avl_set.hpp index 91e2dbb..9e17aa7 100644 --- a/include/boost/intrusive/avl_set.hpp +++ b/include/boost/intrusive/avl_set.hpp @@ -86,8 +86,8 @@ class avl_set_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - avl_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avl_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} @@ -1381,8 +1381,8 @@ class avl_multiset_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor/operator() of the value_compare object throws. - avl_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avl_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} diff --git a/include/boost/intrusive/avltree.hpp b/include/boost/intrusive/avltree.hpp index 71e7943..b6311c4 100644 --- a/include/boost/intrusive/avltree.hpp +++ b/include/boost/intrusive/avltree.hpp @@ -219,8 +219,8 @@ class avltree_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. Basic guarantee. - avltree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avltree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : data_(cmp, v_traits) { node_algorithms::init_header(this->priv_header_ptr()); @@ -542,9 +542,9 @@ class avltree_impl template void insert_equal(Iterator b, Iterator e) { - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end_, *b); + this->insert_equal(iend, *b); } //! Requires: value must be an lvalue @@ -608,9 +608,9 @@ class avltree_impl void insert_unique(Iterator b, Iterator e) { if(this->empty()){ - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_unique(end_, *b); + this->insert_unique(iend, *b); } else{ for (; b != e; ++b) @@ -1249,7 +1249,7 @@ class avltree_impl //! Requires: KeyValueCompare is a function object that induces a strict weak //! ordering compatible with the strict weak ordering used to create the - //! the tree. + //! the tree. //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. //! @@ -1298,7 +1298,7 @@ class avltree_impl //! Requires: KeyValueCompare is a function object that induces a strict weak //! ordering compatible with the strict weak ordering used to create the - //! the tree. + //! the tree. //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. //! diff --git a/include/boost/intrusive/circular_list_algorithms.hpp b/include/boost/intrusive/circular_list_algorithms.hpp index 282f474..5add320 100644 --- a/include/boost/intrusive/circular_list_algorithms.hpp +++ b/include/boost/intrusive/circular_list_algorithms.hpp @@ -174,7 +174,7 @@ class circular_list_algorithms NodeTraits::set_previous(this_node, prev); NodeTraits::set_next(this_node, nxt_node); //nxt_node might be an alias for prev->next_ - //so use it before update it before NodeTraits::set_next(prev, ...) + //so use it before NodeTraits::set_next(prev, ...) //is called and the reference changes it's value NodeTraits::set_previous(nxt_node, this_node); NodeTraits::set_next(prev, this_node); diff --git a/include/boost/intrusive/detail/tree_algorithms.hpp b/include/boost/intrusive/detail/tree_algorithms.hpp index acdedd9..27c8667 100644 --- a/include/boost/intrusive/detail/tree_algorithms.hpp +++ b/include/boost/intrusive/detail/tree_algorithms.hpp @@ -1020,7 +1020,7 @@ class tree_algorithms if(hint == header || comp(key, hint)){ node_ptr prev(hint); //Previous value should be less than the key - if(hint == begin_node(header)|| comp((prev = prev_node(hint)), key)){ + if(hint == begin_node(header) || comp((prev = prev_node(hint)), key)){ commit_data.link_left = unique(header) || !NodeTraits::get_left(hint); commit_data.node = commit_data.link_left ? hint : prev; if(pdepth){ diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index 1ade4d3..eaf834c 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -424,20 +424,20 @@ struct group_functions { node_ptr nxt_ptr(node_traits::get_next(to_erase_ptr)); node_ptr prev_in_group_ptr(group_traits::get_next(to_erase_ptr)); - bool last_in_group_bool = (end_ptr == nxt_ptr) || + bool last_in_group = (end_ptr == nxt_ptr) || (group_traits::get_next(nxt_ptr) != to_erase_ptr); - bool first_in_group_bool = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr; + bool is_first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr; - if(first_in_group_bool && last_in_group_bool){ + if(is_first_in_group && last_in_group){ group_algorithms::init(to_erase_ptr); } - else if(first_in_group_bool){ + else if(is_first_in_group){ group_algorithms::unlink_after(nxt_ptr); } - else if(last_in_group_bool){ - node_ptr first_in_group_ptr = + else if(last_in_group){ + node_ptr first_in_group = get_first_in_group_of_last_in_group(to_erase_ptr); - group_algorithms::unlink_after(first_in_group_ptr); + group_algorithms::unlink_after(first_in_group); } else{ group_algorithms::unlink_after(nxt_ptr); @@ -888,20 +888,20 @@ class hashtable_impl //! //! Notes: buckets array must be disposed only after //! *this is disposed. - hashtable_impl ( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) + explicit hashtable_impl ( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) : data_(b_traits, hash_func, equal_func, v_traits) { this->priv_initialize_buckets(); this->priv_size_traits().set_size(size_type(0)); - size_type bucket_size_ = this->priv_bucket_count(); - BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_size_ != 0); + size_type bucket_sz = this->priv_bucket_count(); + BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0); //Check power of two bucket array if the option is activated BOOST_INTRUSIVE_INVARIANT_ASSERT - (!power_2_buckets || (0 == (bucket_size_ & (bucket_size_-1)))); - this->priv_split_traits().set_size(bucket_size_>>1); + (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1)))); + this->priv_split_traits().set_size(bucket_sz>>1); } //! Effects: to-do @@ -1026,9 +1026,9 @@ class hashtable_impl return this->begin() == this->end(); } else{ - size_type bucket_count_ = this->priv_bucket_count(); + size_type bucket_cnt = this->priv_bucket_count(); const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer()); - for (size_type n = 0; n < bucket_count_; ++n, ++b){ + for (size_type n = 0; n < bucket_cnt; ++n, ++b){ if(!b->empty()){ return false; } @@ -1049,9 +1049,9 @@ class hashtable_impl return this->priv_size_traits().get_size(); else{ size_type len = 0; - size_type bucket_count_ = this->priv_bucket_count(); + size_type bucket_cnt = this->priv_bucket_count(); const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer()); - for (size_type n = 0; n < bucket_count_; ++n, ++b){ + for (size_type n = 0; n < bucket_cnt; ++n, ++b){ len += b->size(); } return len; @@ -1468,9 +1468,9 @@ class hashtable_impl siterator first_local_it(b.slist_it()); size_type first_bucket_num = this->priv_get_bucket_num(first_local_it); - const bucket_ptr bucket_pointer_ = this->priv_bucket_pointer(); + const bucket_ptr buck_ptr = this->priv_bucket_pointer(); siterator before_first_local_it - = this->priv_get_previous(bucket_pointer_[first_bucket_num], first_local_it); + = this->priv_get_previous(buck_ptr[first_bucket_num], first_local_it); size_type last_bucket_num; siterator last_local_it; @@ -1478,7 +1478,7 @@ class hashtable_impl //of the last bucket if(e == this->end()){ last_bucket_num = this->bucket_count() - 1; - last_local_it = bucket_pointer_[last_bucket_num].end(); + last_local_it = buck_ptr[last_bucket_num].end(); } else{ last_local_it = e.slist_it(); @@ -1533,7 +1533,7 @@ class hashtable_impl siterator it = this->priv_find(key, hash_func, equal_func, bucket_num, h, prev); bool success = it != this->priv_invalid_local_it(); - size_type count_(0); + size_type cnt(0); if(!success){ return 0; } @@ -1541,12 +1541,12 @@ class hashtable_impl siterator last = bucket_type::s_iterator_to (*node_traits::get_next(group_functions_t::get_last_in_group (hashtable_impl::dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()))); - this->priv_erase_range_impl(bucket_num, prev, last, disposer, count_); + this->priv_erase_range_impl(bucket_num, prev, last, disposer, cnt); } else{ //If found erase all equal values bucket_type &b = this->priv_bucket_pointer()[bucket_num]; - for(siterator end_ = b.end(); it != end_; ++count_, ++it){ + for(siterator end_sit = b.end(); it != end_sit; ++cnt, ++it){ slist_node_ptr n(it.pointed_node()); const value_type &v = this->priv_value_from_slist_node(n); if(compare_hash){ @@ -1563,7 +1563,7 @@ class hashtable_impl b.erase_after_and_dispose(prev, it, make_node_disposer(disposer)); } this->priv_erasure_update_cache(); - return count_; + return cnt; } //! Effects: Erases all of the elements. @@ -1630,9 +1630,9 @@ class hashtable_impl template size_type count(const KeyType &key, const KeyHasher &hash_func, const KeyValueEqual &equal_func) const { - size_type bucket_n1, bucket_n2, count_; - this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count_); - return count_; + size_type bucket_n1, bucket_n2, cnt; + this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); + return cnt; } //! Effects: Finds an iterator to the first element is equal to @@ -1746,9 +1746,9 @@ class hashtable_impl std::pair equal_range (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) { - size_type bucket_n1, bucket_n2, count_; + size_type bucket_n1, bucket_n2, cnt; std::pair ret = this->priv_equal_range - (key, hash_func, equal_func, bucket_n1, bucket_n2, count_); + (key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); return std::pair (iterator(ret.first, this), iterator(ret.second, this)); } @@ -1788,9 +1788,9 @@ class hashtable_impl std::pair equal_range (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const { - size_type bucket_n1, bucket_n2, count_; + size_type bucket_n1, bucket_n2, cnt; std::pair ret = - this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count_); + this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); return std::pair (const_iterator(ret.first, this), const_iterator(ret.second, this)); } @@ -2102,9 +2102,9 @@ class hashtable_impl if(!fast_shrink){ siterator before_i(old_bucket.before_begin()); - siterator end_(old_bucket.end()); + siterator end_sit(old_bucket.end()); siterator i(old_bucket.begin()); - for(;i != end_; ++i){ + for(;i != end_sit; ++i){ const value_type &v = this->priv_value_from_slist_node(i.pointed_node()); const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t()); const size_type new_n = this->priv_hash_to_bucket(hash_value, new_bucket_count, new_bucket_count); @@ -2159,19 +2159,19 @@ class hashtable_impl { //This function is only available for containers with incremental hashing BOOST_STATIC_ASSERT(( incremental && power_2_buckets )); - const size_type split_idx = this->priv_split_traits().get_size(); - const size_type bucket_count_ = this->priv_bucket_count(); - const bucket_ptr bucket_pointer_ = this->priv_bucket_pointer(); + const size_type split_idx = this->priv_split_traits().get_size(); + const size_type bucket_cnt = this->priv_bucket_count(); + const bucket_ptr buck_ptr = this->priv_bucket_pointer(); if(grow){ //Test if the split variable can be changed - if(split_idx >= bucket_count_) + if(split_idx >= bucket_cnt) return false; - const size_type bucket_to_rehash = split_idx - bucket_count_/2; - bucket_type &old_bucket = bucket_pointer_[bucket_to_rehash]; + const size_type bucket_to_rehash = split_idx - bucket_cnt/2; + bucket_type &old_bucket = buck_ptr[bucket_to_rehash]; siterator before_i(old_bucket.before_begin()); - const siterator end_(old_bucket.end()); + const siterator end_sit(old_bucket.end()); siterator i(old_bucket.begin()); this->priv_split_traits().increment(); @@ -2179,8 +2179,8 @@ class hashtable_impl //moving elements from old_bucket to the target bucket, all moved //elements are moved back to the original one. detail::incremental_rehash_rollback rollback - ( bucket_pointer_[split_idx], old_bucket, this->priv_split_traits()); - for(;i != end_; ++i){ + ( buck_ptr[split_idx], old_bucket, this->priv_split_traits()); + for(;i != end_sit; ++i){ const value_type &v = this->priv_value_from_slist_node(i.pointed_node()); const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t()); const size_type new_n = this->priv_hash_to_bucket(hash_value); @@ -2191,7 +2191,7 @@ class hashtable_impl before_i = last; } else{ - bucket_type &new_b = bucket_pointer_[new_n]; + bucket_type &new_b = buck_ptr[new_n]; new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last); } i = before_i; @@ -2202,11 +2202,11 @@ class hashtable_impl } else{ //Test if the split variable can be changed - if(split_idx <= bucket_count_/2) + if(split_idx <= bucket_cnt/2) return false; - const size_type target_bucket_num = split_idx - 1 - bucket_count_/2; - bucket_type &target_bucket = bucket_pointer_[target_bucket_num]; - bucket_type &source_bucket = bucket_pointer_[split_idx-1]; + const size_type target_bucket_num = split_idx - 1 - bucket_cnt/2; + bucket_type &target_bucket = buck_ptr[target_bucket_num]; + bucket_type &source_bucket = buck_ptr[split_idx-1]; target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket); this->priv_split_traits().decrement(); this->priv_insertion_update_cache(target_bucket_num); @@ -2324,20 +2324,20 @@ class hashtable_impl std::size_t priv_hash_to_bucket(std::size_t hash_value) const { return this->priv_hash_to_bucket(hash_value, this->priv_real_bucket_traits().bucket_count(), this->priv_split_traits().get_size()); } - std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_count_, std::size_t split) const + std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, std::size_t split) const { - std::size_t bucket_number = hashtable_impl::priv_hash_to_bucket_impl(hash_value, bucket_count_, power_2_buckets_t()); + std::size_t bucket_number = hashtable_impl::priv_hash_to_bucket_impl(hash_value, bucket_cnt, power_2_buckets_t()); if(incremental) if(bucket_number >= split) - bucket_number -= bucket_count_/2; + bucket_number -= bucket_cnt/2; return bucket_number; } - static std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_count, detail::false_) - { return hash_value % bucket_count; } + static std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_cnt, detail::false_) + { return hash_value % bucket_cnt; } - static std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_count, detail::true_) - { return hash_value & (bucket_count - 1); } + static std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_cnt, detail::true_) + { return hash_value & (bucket_cnt - 1); } const key_equal &priv_equal() const { return static_cast(this->data_.internal_.bucket_hash_equal_.get()); } @@ -2413,20 +2413,20 @@ class hashtable_impl template void priv_erase_range_impl - (size_type bucket_num, siterator before_first_it, siterator end_, Disposer disposer, size_type &num_erased) + (size_type bucket_num, siterator before_first_it, siterator end_sit, Disposer disposer, size_type &num_erased) { const bucket_ptr buckets = this->priv_bucket_pointer(); bucket_type &b = buckets[bucket_num]; - if(before_first_it == b.before_begin() && end_ == b.end()){ + if(before_first_it == b.before_begin() && end_sit == b.end()){ this->priv_erase_range_impl(bucket_num, 1, disposer, num_erased); } else{ num_erased = 0; siterator to_erase(before_first_it); ++to_erase; - slist_node_ptr end_ptr = end_.pointed_node(); - while(to_erase != end_){ + slist_node_ptr end_ptr = end_sit.pointed_node(); + while(to_erase != end_sit){ group_functions_t::erase_from_group(end_ptr, hashtable_impl::dcast_bucket_ptr(to_erase.pointed_node()), optimize_multikey_t()); to_erase = b.erase_after_and_dispose(before_first_it, make_node_disposer(disposer)); ++num_erased; @@ -2447,8 +2447,8 @@ class hashtable_impl siterator b_begin(b.before_begin()); siterator nxt(b_begin); ++nxt; - siterator end_(b.end()); - while(nxt != end_){ + siterator end_sit(b.end()); + while(nxt != end_sit){ group_functions_t::init_group(hashtable_impl::dcast_bucket_ptr(nxt.pointed_node()), optimize_multikey_t()); nxt = b.erase_after_and_dispose (b_begin, make_node_disposer(disposer)); @@ -2648,8 +2648,8 @@ class hashtable_impl siterator priv_begin(detail::false_) const { size_type n = 0; - size_type bucket_count_ = this->priv_bucket_count(); - for (n = 0; n < bucket_count_; ++n){ + size_type bucket_cnt = this->priv_bucket_count(); + for (n = 0; n < bucket_cnt; ++n){ bucket_type &b = this->priv_bucket_pointer()[n]; if(!b.empty()){ return b.begin(); @@ -2772,9 +2772,9 @@ class hashtable_impl void priv_initialize_buckets() { this->priv_clear_buckets(this->priv_bucket_pointer(), this->priv_bucket_count()); } - void priv_clear_buckets(bucket_ptr buckets_ptr, size_type bucket_count_) + void priv_clear_buckets(bucket_ptr buckets_ptr, size_type bucket_cnt) { - for(; bucket_count_--; ++buckets_ptr){ + for(; bucket_cnt--; ++buckets_ptr){ if(safemode_or_autounlink){ hashtable_impl::priv_clear_group_nodes(*buckets_ptr, optimize_multikey_t()); buckets_ptr->clear_and_dispose(detail::init_disposer()); @@ -2877,10 +2877,10 @@ class hashtable_impl , KeyValueEqual equal_func , size_type &bucket_number_first , size_type &bucket_number_second - , size_type &count_) const + , size_type &cnt) const { std::size_t h; - count_ = 0; + cnt = 0; siterator prev; //Let's see if the element is present std::pair to_return @@ -2890,43 +2890,43 @@ class hashtable_impl bucket_number_second = bucket_number_first; return to_return; } - //If it's present, find the first that it's not equal in - //the same bucket { - bucket_type &b = this->priv_bucket_pointer()[bucket_number_first]; - siterator it = to_return.first; - if(optimize_multikey){ - to_return.second = bucket_type::s_iterator_to - (*node_traits::get_next(group_functions_t::get_last_in_group - (hashtable_impl::dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()))); - count_ = std::distance(it, to_return.second); - if(to_return.second != b.end()){ - bucket_number_second = bucket_number_first; - return to_return; - } - } - else{ - ++count_; - ++it; - while(it != b.end()){ - const value_type &v = this->priv_value_from_slist_node(it.pointed_node()); - if(compare_hash){ - std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t()); - if(hv != h || !equal_func(key, v)){ - to_return.second = it; - bucket_number_second = bucket_number_first; - return to_return; - } - } - else if(!equal_func(key, v)){ - to_return.second = it; - bucket_number_second = bucket_number_first; - return to_return; - } - ++it; - ++count_; - } - } + //If it's present, find the first that it's not equal in + //the same bucket + bucket_type &b = this->priv_bucket_pointer()[bucket_number_first]; + siterator it = to_return.first; + if(optimize_multikey){ + to_return.second = bucket_type::s_iterator_to + (*node_traits::get_next(group_functions_t::get_last_in_group + (hashtable_impl::dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()))); + cnt = std::distance(it, to_return.second); + if(to_return.second != b.end()){ + bucket_number_second = bucket_number_first; + return to_return; + } + } + else{ + ++cnt; + ++it; + while(it != b.end()){ + const value_type &v = this->priv_value_from_slist_node(it.pointed_node()); + if(compare_hash){ + std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t()); + if(hv != h || !equal_func(key, v)){ + to_return.second = it; + bucket_number_second = bucket_number_first; + return to_return; + } + } + else if(!equal_func(key, v)){ + to_return.second = it; + bucket_number_second = bucket_number_first; + return to_return; + } + ++it; + ++cnt; + } + } } //If we reached the end, find the first, non-empty bucket diff --git a/include/boost/intrusive/list.hpp b/include/boost/intrusive/list.hpp index 6024da6..fb2c89a 100644 --- a/include/boost/intrusive/list.hpp +++ b/include/boost/intrusive/list.hpp @@ -202,7 +202,7 @@ class list_impl //! //! Throws: If real_value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). - list_impl(const value_traits &v_traits = value_traits()) + explicit list_impl(const value_traits &v_traits = value_traits()) : data_(v_traits) { this->priv_size_traits().set_size(size_type(0)); @@ -916,9 +916,9 @@ class list_impl } //! Requires: p must be a valid iterator of *this. - //! start and end must point to elements contained in list x. + //! f and e must point to elements contained in list x. //! - //! Effects: Transfers the range pointed by start and end from list x to this list, + //! Effects: Transfers the range pointed by f and e from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing. @@ -928,19 +928,19 @@ class list_impl //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end_) + void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) { if(constant_time_size) - this->splice(p, x, start, end_, std::distance(start, end_)); + this->splice(p, x, f, e, std::distance(f, e)); else - this->splice(p, x, start, end_, 1);//distance is a dummy value + this->splice(p, x, f, e, 1);//distance is a dummy value } //! Requires: p must be a valid iterator of *this. - //! start and end must point to elements contained in list x. - //! n == std::distance(start, end) + //! f and e must point to elements contained in list x. + //! n == std::distance(f, e) //! - //! Effects: Transfers the range pointed by start and end from list x to this list, + //! Effects: Transfers the range pointed by f and e from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing. @@ -949,19 +949,19 @@ class list_impl //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end_, difference_type n) + void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, difference_type n) { if(n){ if(constant_time_size){ size_traits &thist = this->priv_size_traits(); size_traits &xt = x.priv_size_traits(); - BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(start, end_)); - node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end_.pointed_node()); + BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(f, e)); + node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); thist.set_size(thist.get_size() + n); xt.set_size(xt.get_size() - n); } else{ - node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end_.pointed_node()); + node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); } } } diff --git a/include/boost/intrusive/rbtree.hpp b/include/boost/intrusive/rbtree.hpp index 2f3ee56..32e6b9e 100644 --- a/include/boost/intrusive/rbtree.hpp +++ b/include/boost/intrusive/rbtree.hpp @@ -224,8 +224,8 @@ class rbtree_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructorof the value_compare object throws. Basic guarantee. - rbtree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit rbtree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : data_(cmp, v_traits) { node_algorithms::init_header(this->priv_header_ptr()); diff --git a/include/boost/intrusive/set.hpp b/include/boost/intrusive/set.hpp index 9a61560..f753a2c 100644 --- a/include/boost/intrusive/set.hpp +++ b/include/boost/intrusive/set.hpp @@ -93,8 +93,8 @@ class set_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} @@ -1394,8 +1394,8 @@ class multiset_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor/operator() of the value_compare object throws. - multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} diff --git a/include/boost/intrusive/sg_set.hpp b/include/boost/intrusive/sg_set.hpp index 9b020cc..e18b021 100644 --- a/include/boost/intrusive/sg_set.hpp +++ b/include/boost/intrusive/sg_set.hpp @@ -84,8 +84,8 @@ class sg_set_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - sg_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit sg_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} @@ -1417,8 +1417,8 @@ class sg_multiset_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor/operator() of the value_compare object throws. - sg_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit sg_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} diff --git a/include/boost/intrusive/sgtree.hpp b/include/boost/intrusive/sgtree.hpp index cda9f7f..91f276f 100644 --- a/include/boost/intrusive/sgtree.hpp +++ b/include/boost/intrusive/sgtree.hpp @@ -370,8 +370,8 @@ class sgtree_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructorof the value_compare object throws. Basic guarantee. - sgtree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit sgtree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : data_(cmp, v_traits) { node_algorithms::init_header(this->priv_header_ptr()); @@ -701,9 +701,9 @@ class sgtree_impl template void insert_equal(Iterator b, Iterator e) { - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end_, *b); + this->insert_equal(iend, *b); } //! Requires: value must be an lvalue @@ -767,9 +767,9 @@ class sgtree_impl void insert_unique(Iterator b, Iterator e) { if(this->empty()){ - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_unique(end_, *b); + this->insert_unique(iend, *b); } else{ for (; b != e; ++b) diff --git a/include/boost/intrusive/slist.hpp b/include/boost/intrusive/slist.hpp index 5ab5bf6..b0629b4 100644 --- a/include/boost/intrusive/slist.hpp +++ b/include/boost/intrusive/slist.hpp @@ -186,10 +186,17 @@ class slist_impl { return this->set_last_node(n, detail::bool_()); } static node_ptr get_last_node(detail::bool_) - { return node_ptr(); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return node_ptr(); + } static void set_last_node(const node_ptr &, detail::bool_) - {} + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + } node_ptr get_last_node(detail::bool_) { return node_ptr(data_.root_plus_size_.last_); } @@ -273,19 +280,56 @@ class slist_impl { return this->get_real_value_traits(detail::bool_()); } public: + + ///@cond + + //! Requires: f and before_l belong to another slist. + //! + //! Effects: Transfers the range [f, before_l] to this + //! list, after the element pointed by prev_pos. + //! No destructors or copy constructors are called. + //! + //! Throws: Nothing. + //! + //! Complexity: Linear to the number of elements transferred + //! if constant_time_size is true. Constant-time otherwise. + //! + //! Note: Iterators of values obtained from list x now point to elements of this + //! list. Iterators of this list and all the references are not invalidated. + //! + //! Warning: Experimental function, don't use it! + slist_impl( const node_ptr & f, const node_ptr & before_l + , size_type n, const value_traits &v_traits = value_traits()) + : data_(v_traits) + { + if(n){ + this->priv_size_traits().set_size(n); + if(cache_last){ + this->set_last_node(before_l); + } + node_traits::set_next(this->get_root_node(), f); + node_traits::set_next(before_l, this->get_end_node()); + } + else{ + this->set_default_constructed_state(); + } + } + + ///@endcond + //! Effects: constructs an empty list. //! //! Complexity: Constant //! //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). - slist_impl(const value_traits &v_traits = value_traits()) + explicit slist_impl(const value_traits &v_traits = value_traits()) : data_(v_traits) { this->set_default_constructed_state(); } //! Requires: Dereferencing iterator must yield an lvalue of type value_type. //! - //! Effects: Constructs a list equal to [first,last). + //! Effects: Constructs a list equal to [b ,e). //! //! Complexity: Linear in std::distance(b, e). No copy constructors are called. //! @@ -406,7 +450,14 @@ class slist_impl void push_back(reference value) { BOOST_STATIC_ASSERT((cache_last)); - this->insert_after(const_iterator(this->get_last_node(), this), value); + node_ptr n = get_real_value_traits().to_node_ptr(value); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n)); + node_algorithms::link_after(this->get_last_node(), n); + if(cache_last){ + this->set_last_node(n); + } + this->priv_size_traits().increment(); } //! Effects: Erases the first element of the list. @@ -573,9 +624,13 @@ class slist_impl //! //! Note: This function is present only if cached_last<> option is true. iterator last() - { return iterator (this->get_last_node(), this); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return iterator (this->get_last_node(), this); + } - //! Effects: Returns a const_iterator to the first element contained in the list. + //! Effects: Returns a const_iterator to the last element contained in the list. //! //! Throws: Nothing. //! @@ -583,9 +638,13 @@ class slist_impl //! //! Note: This function is present only if cached_last<> option is true. const_iterator last() const - { return const_iterator (this->get_last_node(), this); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return const_iterator (this->get_last_node(), this); + } - //! Effects: Returns a const_iterator to the first element contained in the list. + //! Effects: Returns a const_iterator to the last element contained in the list. //! //! Throws: Nothing. //! @@ -749,7 +808,7 @@ class slist_impl //! an lvalue of type value_type and prev_p must point to an element //! contained by the list or to the end node. //! - //! Effects: Inserts the [first, last) + //! Effects: Inserts the [f, l) //! after the position prev_p. //! //! Throws: Nothing. @@ -758,10 +817,10 @@ class slist_impl //! //! Note: Does not affect the validity of iterators and references. template - void insert_after(const_iterator prev_p, Iterator first, Iterator last_) + void insert_after(const_iterator prev_p, Iterator f, Iterator l) { - for (; first != last_; ++first) - prev_p = this->insert_after(prev_p, *first); + for (; f != l; ++f) + prev_p = this->insert_after(prev_p, *f); } //! Requires: value must be an lvalue and p must point to an element @@ -812,7 +871,7 @@ class slist_impl iterator erase_after(const_iterator prev) { return this->erase_after_and_dispose(prev, detail::null_disposer()); } - //! Effects: Erases the range (before_first, last) from + //! Effects: Erases the range (before_f, l) from //! the list. No destructors are called. //! //! Returns: the first element remaining beyond the removed elements, @@ -825,26 +884,26 @@ class slist_impl //! //! Note: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase_after(const_iterator before_first, const_iterator last_) + iterator erase_after(const_iterator before_f, const_iterator l) { if(safemode_or_autounlink || constant_time_size){ - return this->erase_after_and_dispose(before_first, last_, detail::null_disposer()); + return this->erase_after_and_dispose(before_f, l, detail::null_disposer()); } else{ - node_ptr bfp = before_first.pointed_node(); - node_ptr lp = last_.pointed_node(); + const node_ptr bfp = before_f.pointed_node(); + const node_ptr lp = l.pointed_node(); if(cache_last){ if(lp == this->get_end_node()){ this->set_last_node(bfp); } } node_algorithms::unlink_after(bfp, lp); - return last_.unconst(); + return l.unconst(); } } - //! Effects: Erases the range (before_first, last) from - //! the list. n must be std::distance(before_first, last) - 1. + //! Effects: Erases the range (before_f, l) from + //! the list. n must be std::distance(before_f, l) - 1. //! No destructors are called. //! //! Returns: the first element remaining beyond the removed elements, @@ -853,19 +912,19 @@ class slist_impl //! Throws: Nothing. //! //! Complexity: constant-time if link_mode is normal_link. - //! Linear to the elements (last - before_first) otherwise. + //! Linear to the elements (l - before_f) otherwise. //! //! Note: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase_after(const_iterator before_first, const_iterator last_, difference_type n) + iterator erase_after(const_iterator before_f, const_iterator l, size_type n) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_first), last_) == difference_type(n)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_f), l) == difference_type(n)); if(safemode_or_autounlink){ - return this->erase_after(before_first, last_); + return this->erase_after(before_f, l); } else{ - node_ptr bfp = before_first.pointed_node(); - node_ptr lp = last_.pointed_node(); + const node_ptr bfp = before_f.pointed_node(); + const node_ptr lp = l.pointed_node(); if(cache_last){ if((lp == this->get_end_node())){ this->set_last_node(bfp); @@ -875,7 +934,7 @@ class slist_impl if(constant_time_size){ this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n); } - return last_.unconst(); + return l.unconst(); } } @@ -894,7 +953,7 @@ class slist_impl iterator erase(const_iterator i) { return this->erase_after(this->previous(i)); } - //! Requires: first and last must be valid iterator to elements in *this. + //! Requires: f and l must be valid iterator to elements in *this. //! //! Effects: Erases the range pointed by b and e. //! No destructors are called. @@ -904,15 +963,15 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Linear to the elements before last. + //! Complexity: Linear to the elements before l. //! //! Note: Invalidates the iterators (but not the references) to the //! erased elements. - iterator erase(const_iterator first, const_iterator last_) - { return this->erase_after(this->previous(first), last_); } + iterator erase(const_iterator f, const_iterator l) + { return this->erase_after(this->previous(f), l); } - //! Effects: Erases the range [first, last) from - //! the list. n must be std::distance(first, last). + //! Effects: Erases the range [f, l) from + //! the list. n must be std::distance(f, l). //! No destructors are called. //! //! Returns: the first element remaining beyond the removed elements, @@ -920,13 +979,13 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: linear to the elements before first if link_mode is normal_link - //! and constant_time_size is activated. Linear to the elements before last otherwise. + //! Complexity: linear to the elements before f if link_mode is normal_link + //! and constant_time_size is activated. Linear to the elements before l otherwise. //! //! Note: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase(const_iterator first, const_iterator last_, difference_type n) - { return this->erase_after(this->previous(first), last_, n); } + iterator erase(const_iterator f, const_iterator l, size_type n) + { return this->erase_after(this->previous(f), l, n); } //! Requires: Disposer::operator()(pointer) shouldn't throw. //! @@ -986,7 +1045,7 @@ class slist_impl //! Requires: Disposer::operator()(pointer) shouldn't throw. //! - //! Effects: Erases the range (before_first, last) from + //! Effects: Erases the range (before_f, l) from //! the list. //! Disposer::operator()(pointer) is called for the removed elements. //! @@ -995,13 +1054,13 @@ class slist_impl //! //! Throws: Nothing. //! - //! Complexity: Lineal to the elements (last - before_first + 1). + //! Complexity: Lineal to the elements (l - before_f + 1). //! //! Note: Invalidates the iterators to the erased element. template - iterator erase_after_and_dispose(const_iterator before_first, const_iterator last_, Disposer disposer) + iterator erase_after_and_dispose(const_iterator before_f, const_iterator l, Disposer disposer) { - node_ptr bfp(before_first.pointed_node()), lp(last_.pointed_node()); + node_ptr bfp(before_f.pointed_node()), lp(l.pointed_node()); node_ptr fp(node_traits::get_next(bfp)); node_algorithms::unlink_after(bfp, lp); while(fp != lp){ @@ -1015,7 +1074,7 @@ class slist_impl if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){ this->set_last_node(bfp); } - return last_.unconst(); + return l.unconst(); } //! Requires: Disposer::operator()(pointer) shouldn't throw. @@ -1043,7 +1102,7 @@ class slist_impl { return this->erase_and_dispose(const_iterator(i), disposer); } #endif - //! Requires: first and last must be valid iterator to elements in *this. + //! Requires: f and l must be valid iterator to elements in *this. //! Disposer::operator()(pointer) shouldn't throw. //! //! Effects: Erases the range pointed by b and e. @@ -1056,13 +1115,13 @@ class slist_impl //! Throws: Nothing. //! //! Complexity: Linear to the number of erased elements plus linear - //! to the elements before first. + //! to the elements before f. //! //! Note: Invalidates the iterators (but not the references) to the //! erased elements. template - iterator erase_and_dispose(const_iterator first, const_iterator last_, Disposer disposer) - { return this->erase_after_and_dispose(this->previous(first), last_, disposer); } + iterator erase_and_dispose(const_iterator f, const_iterator l, Disposer disposer) + { return this->erase_after_and_dispose(this->previous(f), l, disposer); } //! Requires: Dereferencing iterator must yield //! an lvalue of type value_type. @@ -1121,23 +1180,23 @@ class slist_impl //! //! Complexity: In general, linear to the elements contained in x. //! Constant-time if cache_last<> option is true and also constant-time if - //! linear<> option is true "this" is empty and "last" is not used. + //! linear<> option is true "this" is empty and "l" is not used. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. //! - //! Additional note: If the optional parameter "last" is provided, it will be + //! Additional note: If the optional parameter "l" is provided, it will be //! assigned to the last spliced element or prev if x is empty. //! This iterator can be used as new "prev" iterator for a new splice_after call. //! that will splice new values after the previously spliced values. - void splice_after(const_iterator prev, slist_impl &x, const_iterator *last_ = 0) + void splice_after(const_iterator prev, slist_impl &x, const_iterator *l = 0) { if(x.empty()){ - if(last_) *last_ = prev; + if(l) *l = prev; } else if(linear && this->empty()){ this->swap(x); - if(last_) *last_ = this->previous(this->cend()); + if(l) *l = this->previous(this->cend()); } else{ const_iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active @@ -1152,7 +1211,7 @@ class slist_impl node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n); this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size()); x.priv_size_traits().set_size(size_type(0)); - if(last_) *last_ = last_x; + if(l) *l = last_x; } } @@ -1176,10 +1235,10 @@ class slist_impl } //! Requires: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end(). + //! before_begin(), and before_f and before_l belong to x and + //! ++before_f != x.end() && before_l != x.end(). //! - //! Effects: Transfers the range (before_first, before_last] from list x to this + //! Effects: Transfers the range (before_f, before_l] from list x to this //! list, after the element pointed by prev_pos. //! No destructors or copy constructors are called. //! @@ -1190,21 +1249,21 @@ class slist_impl //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last) + void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l) { if(constant_time_size) - this->splice_after(prev_pos, x, before_first, before_last, std::distance(before_first, before_last)); + this->splice_after(prev_pos, x, before_f, before_l, std::distance(before_f, before_l)); else this->priv_splice_after - (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node()); + (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node()); } //! Requires: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end() and - //! n == std::distance(before_first, before_last). + //! before_begin(), and before_f and before_l belong to x and + //! ++before_f != x.end() && before_l != x.end() and + //! n == std::distance(before_f, before_l). //! - //! Effects: Transfers the range (before_first, before_last] from list x to this + //! Effects: Transfers the range (before_f, before_l] from list x to this //! list, after the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing. @@ -1213,16 +1272,14 @@ class slist_impl //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last, difference_type n) + void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l, size_type n) { - if(n){ - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_first, before_last) == n); - this->priv_splice_after - (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node()); - if(constant_time_size){ - this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n); - x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n); - } + BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_f, before_l) == difference_type(n)); + this->priv_splice_after + (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node()); + if(constant_time_size){ + this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n); + x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n); } } @@ -1243,12 +1300,12 @@ class slist_impl //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. //! - //! Additional note: If the optional parameter "last" is provided, it will be + //! Additional note: If the optional parameter "l" is provided, it will be //! assigned to the last spliced element or prev if x is empty. //! This iterator can be used as new "prev" iterator for a new splice_after call. //! that will splice new values after the previously spliced values. - void splice(const_iterator it, slist_impl &x, const_iterator *last_ = 0) - { this->splice_after(this->previous(it), x, last_); } + void splice(const_iterator it, slist_impl &x, const_iterator *l = 0) + { this->splice_after(this->previous(it), x, l); } //! Requires: it p must be a valid iterator of *this. //! elem must point to an element contained in list @@ -1268,43 +1325,43 @@ class slist_impl { return this->splice_after(this->previous(pos), x, x.previous(elem)); } //! Requires: pos must be a dereferenceable iterator in *this - //! and first and last belong to x and first and last a valid range on x. + //! and f and f belong to x and f and f a valid range on x. //! - //! Effects: Transfers the range [first, last) from list x to this + //! Effects: Transfers the range [f, l) from list x to this //! list, before the element pointed by pos. //! No destructors or copy constructors are called. //! //! Throws: Nothing. //! - //! Complexity: Linear to the sum of elements before pos, first, and last + //! Complexity: Linear to the sum of elements before pos, f, and l //! plus linear to the number of elements transferred if constant_time_size is true. - //! Linear to the sum of elements before first, and last + //! Linear to the sum of elements before f, and l //! plus linear to the number of elements transferred if constant_time_size is true //! if cache_last<> is true and pos == end() //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last_) - { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last_)); } + void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l) + { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l)); } //! Requires: pos must be a dereferenceable iterator in *this - //! and first and last belong to x and first and last a valid range on x. - //! n == std::distance(first, last). + //! and f and l belong to x and f and l a valid range on x. + //! n == std::distance(f, l). //! - //! Effects: Transfers the range [first, last) from list x to this + //! Effects: Transfers the range [f, l) from list x to this //! list, before the element pointed by pos. //! No destructors or copy constructors are called. //! //! Throws: Nothing. //! - //! Complexity: Linear to the sum of elements before pos, first, and last. - //! Linear to the sum of elements before first and last + //! Complexity: Linear to the sum of elements before pos, f, and l. + //! Linear to the sum of elements before f and l //! if cache_last<> is true and pos == end(). //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last_, difference_type n) - { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last_), n); } + void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l, size_type n) + { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l), n); } //! Effects: This function sorts the list *this according to std::less. //! The sort is stable, that is, the relative order of equivalent elements is preserved. @@ -1402,14 +1459,14 @@ class slist_impl //! //! Note: Iterators and references are not invalidated. //! - //! Additional note: If optional "last" argument is passed, it is assigned + //! Additional note: If optional "l" argument is passed, it is assigned //! to an iterator to the last transferred value or end() is x is empty. template - void merge(slist_impl& x, Predicate p, const_iterator *last_ = 0) + void merge(slist_impl& x, Predicate p, const_iterator *l = 0) { const_iterator e(this->cend()), ex(x.cend()), bb(this->cbefore_begin()), bb_next; - if(last_) *last_ = e.unconst(); + if(l) *l = e.unconst(); while(!x.empty()){ const_iterator ibx_next(x.cbefore_begin()), ibx(ibx_next++); while (++(bb_next = bb) != e && !p(*ibx_next, *bb_next)){ @@ -1417,7 +1474,7 @@ class slist_impl } if(bb_next == e){ //Now transfer the rest to the end of the container - this->splice_after(bb, x, last_); + this->splice_after(bb, x, l); break; } else{ @@ -1426,7 +1483,7 @@ class slist_impl ibx = ibx_next; ++n; } while(++(ibx_next = ibx) != ex && p(*ibx_next, *bb_next)); this->splice_after(bb, x, x.before_begin(), ibx, n); - if(last_) *last_ = ibx; + if(l) *l = ibx; } } } @@ -1728,11 +1785,12 @@ class slist_impl (prev_from.pointed_node(), i.pointed_node()), this); } + ///@cond + //! Requires: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end(). + //! before_begin(), and f and before_l belong to another slist. //! - //! Effects: Transfers the range (before_first, before_last] to this + //! Effects: Transfers the range [f, before_l] to this //! list, after the element pointed by prev_pos. //! No destructors or copy constructors are called. //! @@ -1741,67 +1799,70 @@ class slist_impl //! Complexity: Linear to the number of elements transferred //! if constant_time_size is true. Constant-time otherwise. //! - //! Note: Iterators of values obtained from list x now point to elements of this - //! list. Iterators of this list and all the references are not invalidated. - void incorporate_after(const_iterator prev_from, const node_ptr & first, const node_ptr & before_last) + //! Note: Iterators of values obtained from the list that owned f and before_l now + //! point to elements of this list. Iterators of this list and all the references are not invalidated. + //! + //! Warning: Experimental function, don't use it! + void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l) { if(constant_time_size) - this->incorporate_after(prev_from, first, before_last, std::distance(first, before_last)+1); + this->incorporate_after(prev_pos, f, before_l, std::distance(f, before_l)+1); else - this->priv_incorporate_after - (prev_from.pointed_node(), first, before_last); + this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l); } //! Requires: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end() and - //! n == std::distance(first, before_last) + 1. + //! before_begin(), and f and before_l belong to another slist. + //! n == std::distance(f, before_l) + 1. //! - //! Effects: Transfers the range (before_first, before_last] from list x to this - //! list, after the element pointed by p. No destructors or copy constructors are called. + //! Effects: Transfers the range [f, before_l] to this + //! list, after the element pointed by prev_pos. + //! No destructors or copy constructors are called. //! //! Throws: Nothing. //! //! Complexity: Constant time. //! - //! Note: Iterators of values obtained from list x now point to elements of this - //! list. Iterators of this list and all the references are not invalidated. - void incorporate_after(const_iterator prev_pos, const node_ptr & first, const node_ptr & before_last, difference_type n) + //! Note: Iterators of values obtained from the list that owned f and before_l now + //! point to elements of this list. Iterators of this list and all the references are not invalidated. + //! + //! Warning: Experimental function, don't use it! + void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l, size_type n) { if(n){ - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(iterator(first, this), iterator(before_last, this))+1 == n); - this->priv_incorporate_after(prev_pos.pointed_node(), first, before_last); + BOOST_INTRUSIVE_INVARIANT_ASSERT(n > 0); + BOOST_INTRUSIVE_INVARIANT_ASSERT(size_type(std::distance(iterator(f, this), iterator(before_l, this)))+1 == n); + this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l); if(constant_time_size){ this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n); } } } + ///@endcond + private: - void priv_splice_after(const node_ptr & prev_pos_n, slist_impl &x, const node_ptr & before_first_n, const node_ptr & before_last_n) + void priv_splice_after(const node_ptr & prev_pos_n, slist_impl &x, const node_ptr & before_f_n, const node_ptr & before_l_n) { - if (before_first_n != before_last_n && prev_pos_n != before_first_n && prev_pos_n != before_last_n) - { - if(cache_last){ - if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ - this->set_last_node(before_last_n); - } - if(node_traits::get_next(before_last_n) == x.get_end_node()){ - x.set_last_node(before_first_n); - } + if (cache_last && (before_f_n != before_l_n)){ + if(prev_pos_n == this->get_last_node()){ + this->set_last_node(before_l_n); + } + if(&x != this && node_traits::get_next(before_l_n) == x.get_end_node()){ + x.set_last_node(before_f_n); } - node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n); } + node_algorithms::transfer_after(prev_pos_n, before_f_n, before_l_n); } - void priv_incorporate_after(const node_ptr & prev_pos_n, const node_ptr & first_n, const node_ptr & before_last_n) + void priv_incorporate_after(const node_ptr & prev_pos_n, const node_ptr & first_n, const node_ptr & before_l_n) { if(cache_last){ - if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ - this->set_last_node(before_last_n); + if(prev_pos_n == this->get_last_node()){ + this->set_last_node(before_l_n); } } - node_algorithms::incorporate_after(prev_pos_n, first_n, before_last_n); + node_algorithms::incorporate_after(prev_pos_n, first_n, before_l_n); } void priv_reverse(detail::bool_) @@ -1816,9 +1877,9 @@ class slist_impl void priv_shift_backwards(size_type n, detail::bool_) { - node_ptr last_ = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n); - if(cache_last && last_){ - this->set_last_node(last_); + node_ptr l = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n); + if(cache_last && l){ + this->set_last_node(l); } } @@ -1837,9 +1898,9 @@ class slist_impl void priv_shift_forward(size_type n, detail::bool_) { - node_ptr last_ = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n); - if(cache_last && last_){ - this->set_last_node(last_); + node_ptr l = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n); + if(cache_last && l){ + this->set_last_node(l); } } @@ -2100,11 +2161,20 @@ class slist typedef typename Base::value_traits value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::size_type size_type; + typedef typename Base::node_ptr node_ptr; - slist(const value_traits &v_traits = value_traits()) + explicit slist(const value_traits &v_traits = value_traits()) : Base(v_traits) {} + struct incorporate_t{}; + + slist( const node_ptr & f, const node_ptr & before_l + , size_type n, const value_traits &v_traits = value_traits()) + : Base(f, before_l, n, v_traits) + {} + template slist(Iterator b, Iterator e, const value_traits &v_traits = value_traits()) : Base(b, e, v_traits) diff --git a/include/boost/intrusive/splay_set.hpp b/include/boost/intrusive/splay_set.hpp index e7f3b94..7cb4978 100644 --- a/include/boost/intrusive/splay_set.hpp +++ b/include/boost/intrusive/splay_set.hpp @@ -86,8 +86,8 @@ class splay_set_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - splay_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splay_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} @@ -1404,8 +1404,8 @@ class splay_multiset_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor/operator() of the value_compare object throws. - splay_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splay_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, v_traits) {} diff --git a/include/boost/intrusive/splaytree.hpp b/include/boost/intrusive/splaytree.hpp index 7d41f69..7c599b7 100644 --- a/include/boost/intrusive/splaytree.hpp +++ b/include/boost/intrusive/splaytree.hpp @@ -214,8 +214,8 @@ class splaytree_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructorof the value_compare object throws. Basic guarantee. - splaytree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splaytree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : data_(cmp, v_traits) { node_algorithms::init_header(this->priv_header_ptr()); @@ -540,9 +540,9 @@ class splaytree_impl void insert_equal(Iterator b, Iterator e) { if(this->empty()){ - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end_, *b); + this->insert_equal(iend, *b); } } diff --git a/include/boost/intrusive/treap.hpp b/include/boost/intrusive/treap.hpp index 99bdb69..53eb2f3 100644 --- a/include/boost/intrusive/treap.hpp +++ b/include/boost/intrusive/treap.hpp @@ -9,8 +9,8 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_TRIE_HPP -#define BOOST_INTRUSIVE_TRIE_HPP +#ifndef BOOST_INTRUSIVE_TREAP_HPP +#define BOOST_INTRUSIVE_TREAP_HPP #include #include @@ -232,9 +232,9 @@ class treap_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare/priority_compare objects throw. Basic guarantee. - treap_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : data_(cmp, pcmp, v_traits) { node_algorithms::init_header(this->priv_header_ptr()); @@ -627,9 +627,9 @@ class treap_impl template void insert_equal(Iterator b, Iterator e) { - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end_, *b); + this->insert_equal(iend, *b); } //! Requires: value must be an lvalue @@ -696,9 +696,9 @@ class treap_impl void insert_unique(Iterator b, Iterator e) { if(this->empty()){ - iterator end_(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_unique(end_, *b); + this->insert_unique(iend, *b); } else{ for (; b != e; ++b) @@ -1879,4 +1879,4 @@ class treap #include -#endif //BOOST_INTRUSIVE_TRIE_HPP +#endif //BOOST_INTRUSIVE_TREAP_HPP diff --git a/include/boost/intrusive/treap_set.hpp b/include/boost/intrusive/treap_set.hpp index 66adfaf..cd1300a 100644 --- a/include/boost/intrusive/treap_set.hpp +++ b/include/boost/intrusive/treap_set.hpp @@ -87,9 +87,9 @@ class treap_set_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - treap_set_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap_set_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, pcmp, v_traits) {} @@ -1498,9 +1498,9 @@ class treap_multiset_impl //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare/priority_compare objects throw. - treap_multiset_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap_multiset_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : tree_(cmp, pcmp, v_traits) {} diff --git a/include/boost/intrusive/unordered_set.hpp b/include/boost/intrusive/unordered_set.hpp index a06d74b..d957f4a 100644 --- a/include/boost/intrusive/unordered_set.hpp +++ b/include/boost/intrusive/unordered_set.hpp @@ -122,10 +122,10 @@ class unordered_set_impl //! //! Notes: buckets array must be disposed only after //! *this is disposed. - unordered_set_impl( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) + explicit unordered_set_impl( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) : table_(b_traits, hash_func, equal_func, v_traits) {} @@ -1193,10 +1193,10 @@ class unordered_multiset_impl //! //! Notes: buckets array must be disposed only after //! *this is disposed. - unordered_multiset_impl ( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) + explicit unordered_multiset_impl ( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) : table_(b_traits, hash_func, equal_func, v_traits) {}