From 81aefde94e67b7cbe606165b6a6f28c43ff346a9 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 23 Feb 2017 20:14:27 +0000 Subject: [PATCH] Use const_key_type internally --- .../boost/unordered/detail/implementation.hpp | 50 +++++++++---------- include/boost/unordered/detail/map.hpp | 10 ++-- include/boost/unordered/detail/set.hpp | 4 +- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 331cbe9f..7e1be8cd 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -2473,7 +2473,7 @@ struct table : boost::unordered::detail::functionshash_function(), k); } @@ -3055,13 +3055,13 @@ struct table : boost::unordered::detail::functions(this)->find_node_impl( key_hash, k, this->key_eq()); } - node_pointer find_node(key_type const& k) const + node_pointer find_node(const_key_type& k) const { return static_cast(this)->find_node_impl( hash(k), k, this->key_eq()); @@ -3379,7 +3379,7 @@ struct table_impl : boost::unordered::detail::table typedef typename table::link_pointer link_pointer; typedef typename table::hasher hasher; typedef typename table::key_equal key_equal; - typedef typename table::key_type key_type; + typedef typename table::const_key_type const_key_type; typedef typename table::node_constructor node_constructor; typedef typename table::node_tmp node_tmp; typedef typename table::extractor extractor; @@ -3453,12 +3453,12 @@ struct table_impl : boost::unordered::detail::table } } - std::size_t count(key_type const& k) const + std::size_t count(const_key_type& k) const { return this->find_node(k) ? 1 : 0; } - value_type& at(key_type const& k) const + value_type& at(const_key_type& k) const { if (this->size_) { node_pointer n = this->find_node(k); @@ -3470,7 +3470,7 @@ struct table_impl : boost::unordered::detail::table std::out_of_range("Unable to find key in unordered_map.")); } - std::pair equal_range(key_type const& k) const + std::pair equal_range(const_key_type& k) const { node_pointer n = this->find_node(k); return std::make_pair(iterator(n), iterator(n ? next_node(n) : n)); @@ -3530,7 +3530,7 @@ struct table_impl : boost::unordered::detail::table return this->add_node(b.release(), key_hash); } - value_type& operator[](key_type const& k) + value_type& operator[](const_key_type& k) { std::size_t key_hash = this->hash(k); node_pointer pos = this->find_node(key_hash, k); @@ -3623,7 +3623,7 @@ struct table_impl : boost::unordered::detail::table template iterator emplace_hint_impl( - c_iterator hint, key_type const& k, BOOST_UNORDERED_EMPLACE_ARGS) + c_iterator hint, const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS) { if (hint.node_ && this->key_eq()(k, this->get_key(*hint))) { return iterator(hint.node_); @@ -3633,7 +3633,7 @@ struct table_impl : boost::unordered::detail::table } template - emplace_return emplace_impl(key_type const& k, BOOST_UNORDERED_EMPLACE_ARGS) + emplace_return emplace_impl(const_key_type& k, BOOST_UNORDERED_EMPLACE_ARGS) { std::size_t key_hash = this->hash(k); node_pointer pos = this->find_node(key_hash, k); @@ -3656,7 +3656,7 @@ struct table_impl : boost::unordered::detail::table node_tmp b(boost::unordered::detail::func::construct_node_from_args( this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD), this->node_alloc()); - key_type const& k = this->get_key(b.node_->value()); + const_key_type& k = this->get_key(b.node_->value()); if (hint.node_ && this->key_eq()(k, this->get_key(*hint))) { return iterator(hint.node_); } @@ -3675,7 +3675,7 @@ struct table_impl : boost::unordered::detail::table node_tmp b(boost::unordered::detail::func::construct_node_from_args( this->node_alloc(), BOOST_UNORDERED_EMPLACE_FORWARD), this->node_alloc()); - key_type const& k = this->get_key(b.node_->value()); + const_key_type& k = this->get_key(b.node_->value()); std::size_t key_hash = this->hash(k); node_pointer pos = this->find_node(key_hash, k); if (pos) { @@ -3700,7 +3700,7 @@ struct table_impl : boost::unordered::detail::table } template - void insert_range_impl(key_type const& k, InputIt i, InputIt j) + void insert_range_impl(const_key_type& k, InputIt i, InputIt j) { insert_range_impl2(k, i, j); @@ -3718,7 +3718,7 @@ struct table_impl : boost::unordered::detail::table } template - void insert_range_impl2(key_type const& k, InputIt i, InputIt j) + void insert_range_impl2(const_key_type& k, InputIt i, InputIt j) { // No side effects in this initial code std::size_t key_hash = this->hash(k); @@ -3748,7 +3748,7 @@ struct table_impl : boost::unordered::detail::table a.alloc_, a.node_->value_ptr(), *i); node_tmp b(a.release(), a.alloc_); - key_type const& k = this->get_key(b.node_->value()); + const_key_type& k = this->get_key(b.node_->value()); std::size_t key_hash = this->hash(k); node_pointer pos = this->find_node(key_hash, k); @@ -3768,7 +3768,7 @@ struct table_impl : boost::unordered::detail::table // // no throw - std::size_t erase_key(key_type const& k) + std::size_t erase_key(const_key_type& k) { if (!this->size_) return 0; @@ -4012,7 +4012,7 @@ struct grouped_table_impl : boost::unordered::detail::table typedef typename table::link_pointer link_pointer; typedef typename table::hasher hasher; typedef typename table::key_equal key_equal; - typedef typename table::key_type key_type; + typedef typename table::const_key_type const_key_type; typedef typename table::node_constructor node_constructor; typedef typename table::node_tmp node_tmp; typedef typename table::extractor extractor; @@ -4091,7 +4091,7 @@ struct grouped_table_impl : boost::unordered::detail::table } } - std::size_t count(key_type const& k) const + std::size_t count(const_key_type& k) const { node_pointer n = this->find_node(k); if (!n) @@ -4107,7 +4107,7 @@ struct grouped_table_impl : boost::unordered::detail::table return x; } - std::pair equal_range(key_type const& k) const + std::pair equal_range(const_key_type& k) const { node_pointer n = this->find_node(k); return std::make_pair(iterator(n), iterator(n ? next_group(n) : n)); @@ -4315,7 +4315,7 @@ struct grouped_table_impl : boost::unordered::detail::table iterator emplace_impl(node_pointer n) { node_tmp a(n, this->node_alloc()); - key_type const& k = this->get_key(a.node_->value()); + const_key_type& k = this->get_key(a.node_->value()); std::size_t key_hash = this->hash(k); node_pointer position = this->find_node(key_hash, k); this->reserve_for_insert(this->size_ + 1); @@ -4325,7 +4325,7 @@ struct grouped_table_impl : boost::unordered::detail::table iterator emplace_hint_impl(c_iterator hint, node_pointer n) { node_tmp a(n, this->node_alloc()); - key_type const& k = this->get_key(a.node_->value()); + const_key_type& k = this->get_key(a.node_->value()); if (hint.node_ && this->key_eq()(k, this->get_key(*hint))) { this->reserve_for_insert(this->size_ + 1); return iterator(this->add_using_hint(a.release(), hint.node_)); @@ -4340,7 +4340,7 @@ struct grouped_table_impl : boost::unordered::detail::table void emplace_impl_no_rehash(node_pointer n) { node_tmp a(n, this->node_alloc()); - key_type const& k = this->get_key(a.node_->value()); + const_key_type& k = this->get_key(a.node_->value()); std::size_t key_hash = this->hash(k); node_pointer position = this->find_node(key_hash, k); this->add_node(a.release(), key_hash, position); @@ -4391,7 +4391,7 @@ struct grouped_table_impl : boost::unordered::detail::table // // no throw - std::size_t erase_key(key_type const& k) + std::size_t erase_key(const_key_type& k) { if (!this->size_) return 0; diff --git a/include/boost/unordered/detail/map.hpp b/include/boost/unordered/detail/map.hpp index 5770e9ec..dc23931b 100644 --- a/include/boost/unordered/detail/map.hpp +++ b/include/boost/unordered/detail/map.hpp @@ -16,7 +16,7 @@ template struct map typedef std::pair value_type; typedef H hasher; typedef P key_equal; - typedef K key_type; + typedef K const const_key_type; typedef typename ::boost::unordered::detail::rebind_wrap::type value_allocator; @@ -29,8 +29,7 @@ template struct map typedef typename pick::link_pointer link_pointer; typedef boost::unordered::detail::table_impl table; - typedef boost::unordered::detail::map_extractor - extractor; + typedef boost::unordered::detail::map_extractor extractor; typedef typename boost::unordered::detail::pick_policy::type policy; @@ -50,7 +49,7 @@ struct multimap typedef std::pair value_type; typedef H hasher; typedef P key_equal; - typedef K key_type; + typedef K const const_key_type; typedef typename ::boost::unordered::detail::rebind_wrap::type value_allocator; @@ -63,8 +62,7 @@ struct multimap typedef typename pick::link_pointer link_pointer; typedef boost::unordered::detail::grouped_table_impl table; - typedef boost::unordered::detail::map_extractor - extractor; + typedef boost::unordered::detail::map_extractor extractor; typedef typename boost::unordered::detail::pick_policy::type policy; diff --git a/include/boost/unordered/detail/set.hpp b/include/boost/unordered/detail/set.hpp index 2eb34207..0370f78f 100644 --- a/include/boost/unordered/detail/set.hpp +++ b/include/boost/unordered/detail/set.hpp @@ -16,7 +16,7 @@ template struct set typedef T value_type; typedef H hasher; typedef P key_equal; - typedef T key_type; + typedef T const const_key_type; typedef typename ::boost::unordered::detail::rebind_wrap::type value_allocator; @@ -48,7 +48,7 @@ template struct multiset typedef T value_type; typedef H hasher; typedef P key_equal; - typedef T key_type; + typedef T const const_key_type; typedef typename ::boost::unordered::detail::rebind_wrap::type value_allocator;