diff options
author | Abseil Team <absl-team@google.com> | 2020-12-03 11:09:28 -0800 |
---|---|---|
committer | Greg Falcon <gfalcon@google.com> | 2020-12-03 20:40:58 +0000 |
commit | acf3390ca28edf1438fa896602ffede2a7dff103 (patch) | |
tree | 9ea833910de876aeb98dfbaff19e1a3766b34c93 /absl/container | |
parent | 592924480acf034aec0454160492a20bccdbdf3e (diff) |
Export of internal Abseil changes
--
8ebcdcac49f299156a8fd4a77501a258050960e8 by Evan Brown <ezb@google.com>:
In btree_iterator, refactor a bit and update a couple of comments.
PiperOrigin-RevId: 345491436
--
421d3b9b5cf484811b9514436ce83f797e109145 by CJ Johnson <johnsoncj@google.com>:
Updates the implementation of InlinedVector to accurately express the value-initialization semantics of the default constructor
PiperOrigin-RevId: 345479151
--
88f36a132b2038cb276ed1ad4d9764adb1fc78e6 by CJ Johnson <johnsoncj@google.com>:
Updates the implementation of InlinedVector to accurately express the value-initialization semantics of the default constructor
PiperOrigin-RevId: 345433064
--
e55c9b4e7c578c1c4f2df65b1991041c283a97d9 by Chris Kennelly <ckennelly@google.com>:
Internal change
PiperOrigin-RevId: 345388181
--
e2284c4e77ff1ebc3009e5bf520524c552226d8a by Chris Kennelly <ckennelly@google.com>:
Internal change
PiperOrigin-RevId: 345357514
--
1c496a2ae07ce98578614155d63ef2ea4de5e518 by Chris Kennelly <ckennelly@google.com>:
Mark string lookup functions noexcept.
PiperOrigin-RevId: 345275012
GitOrigin-RevId: 8ebcdcac49f299156a8fd4a77501a258050960e8
Change-Id: I0ccb57d210b543270769e1378de38bf0922f8745
Diffstat (limited to 'absl/container')
-rw-r--r-- | absl/container/internal/btree.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/absl/container/internal/btree.h b/absl/container/internal/btree.h index f2fc31df..dad580f5 100644 --- a/absl/container/internal/btree.h +++ b/absl/container/internal/btree.h @@ -910,6 +910,7 @@ struct btree_iterator { using key_type = typename Node::key_type; using size_type = typename Node::size_type; using params_type = typename Node::params_type; + using is_map_container = typename params_type::is_map_container; using node_type = Node; using normal_node = typename std::remove_const<Node>::type; @@ -921,7 +922,7 @@ struct btree_iterator { using slot_type = typename params_type::slot_type; using iterator = - btree_iterator<normal_node, normal_reference, normal_pointer>; + btree_iterator<normal_node, normal_reference, normal_pointer>; using const_iterator = btree_iterator<const_node, const_reference, const_pointer>; @@ -938,20 +939,19 @@ struct btree_iterator { btree_iterator(Node *n, int p) : node(n), position(p) {} // NOTE: this SFINAE allows for implicit conversions from iterator to - // const_iterator, but it specifically avoids defining copy constructors so - // that btree_iterator can be trivially copyable. This is for performance and - // binary size reasons. + // const_iterator, but it specifically avoids hiding the copy constructor so + // that the trivial one will be used when possible. template <typename N, typename R, typename P, absl::enable_if_t< std::is_same<btree_iterator<N, R, P>, iterator>::value && std::is_same<btree_iterator, const_iterator>::value, int> = 0> - btree_iterator(const btree_iterator<N, R, P> &other) // NOLINT + btree_iterator(const btree_iterator<N, R, P> other) // NOLINT : node(other.node), position(other.position) {} private: // This SFINAE allows explicit conversions from const_iterator to - // iterator, but also avoids defining a copy constructor. + // iterator, but also avoids hiding the copy constructor. // NOTE: the const_cast is safe because this constructor is only called by // non-const methods and the container owns the nodes. template <typename N, typename R, typename P, @@ -959,7 +959,7 @@ struct btree_iterator { std::is_same<btree_iterator<N, R, P>, const_iterator>::value && std::is_same<btree_iterator, iterator>::value, int> = 0> - explicit btree_iterator(const btree_iterator<N, R, P> &other) + explicit btree_iterator(const btree_iterator<N, R, P> other) : node(const_cast<node_type *>(other.node)), position(other.position) {} // Increment/decrement the iterator. @@ -1022,6 +1022,8 @@ struct btree_iterator { } private: + friend iterator; + friend const_iterator; template <typename Params> friend class btree; template <typename Tree> @@ -1032,8 +1034,6 @@ struct btree_iterator { friend class btree_map_container; template <typename Tree> friend class btree_multiset_container; - template <typename N, typename R, typename P> - friend struct btree_iterator; template <typename TreeType, typename CheckerType> friend class base_checker; @@ -1122,7 +1122,8 @@ class btree { using const_reference = typename Params::const_reference; using pointer = typename Params::pointer; using const_pointer = typename Params::const_pointer; - using iterator = btree_iterator<node_type, reference, pointer>; + using iterator = + typename btree_iterator<node_type, reference, pointer>::iterator; using const_iterator = typename iterator::const_iterator; using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>; @@ -1135,7 +1136,11 @@ class btree { private: // For use in copy_or_move_values_in_order. const value_type &maybe_move_from_iterator(const_iterator it) { return *it; } - value_type &&maybe_move_from_iterator(iterator it) { return std::move(*it); } + value_type &&maybe_move_from_iterator(iterator it) { + // This is a destructive operation on the other container so it's safe for + // us to const_cast and move from the keys here even if it's a set. + return std::move(const_cast<value_type &>(*it)); + } // Copies or moves (depending on the template parameter) the values in // other into this btree in their order in other. This btree must be empty |