OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_CONTAINERS_FLAT_TREE_H_ | 5 #ifndef BASE_CONTAINERS_FLAT_TREE_H_ |
6 #define BASE_CONTAINERS_FLAT_TREE_H_ | 6 #define BASE_CONTAINERS_FLAT_TREE_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 } | 241 } |
242 | 242 |
243 friend bool operator<=(const flat_tree& lhs, const flat_tree& rhs) { | 243 friend bool operator<=(const flat_tree& lhs, const flat_tree& rhs) { |
244 return !(lhs > rhs); | 244 return !(lhs > rhs); |
245 } | 245 } |
246 | 246 |
247 friend void swap(flat_tree& lhs, flat_tree& rhs) { lhs.swap(rhs); } | 247 friend void swap(flat_tree& lhs, flat_tree& rhs) { lhs.swap(rhs); } |
248 | 248 |
249 protected: | 249 protected: |
250 // Emplaces a new item into the tree that is known not to be in it. This | 250 // Emplaces a new item into the tree that is known not to be in it. This |
251 // is for implementing map [] and at(). | 251 // is for implementing map operator[]. |
252 template <class... Args> | 252 template <class... Args> |
253 iterator unsafe_emplace(const_iterator position, Args&&... args); | 253 iterator unsafe_emplace(const_iterator position, Args&&... args); |
254 | 254 |
255 private: | 255 private: |
256 // Helper class for e.g. lower_bound that can compare a value on the left | 256 // Helper class for e.g. lower_bound that can compare a value on the left |
257 // to a key on the right. | 257 // to a key on the right. |
258 struct KeyValueCompare { | 258 struct KeyValueCompare { |
259 // The key comparison object must outlive this class. | 259 // The key comparison object must outlive this class. |
260 explicit KeyValueCompare(const key_compare& key_comp) | 260 explicit KeyValueCompare(const key_compare& key_comp) |
261 : key_comp_(key_comp) {} | 261 : key_comp_(key_comp) {} |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 flat_tree& other) { | 676 flat_tree& other) { |
677 std::swap(impl_, other.impl_); | 677 std::swap(impl_, other.impl_); |
678 } | 678 } |
679 | 679 |
680 template <class Key, class Value, class GetKeyFromValue, class KeyCompare> | 680 template <class Key, class Value, class GetKeyFromValue, class KeyCompare> |
681 template <class... Args> | 681 template <class... Args> |
682 auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::unsafe_emplace( | 682 auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::unsafe_emplace( |
683 const_iterator position, | 683 const_iterator position, |
684 Args&&... args) -> iterator { | 684 Args&&... args) -> iterator { |
685 // We have to cast away const because of crbug.com/677044. | 685 // We have to cast away const because of crbug.com/677044. |
686 return impl_.body_.insert(const_cast_it(position), | 686 return impl_.body_.emplace(const_cast_it(position), |
687 value_type(std::forward<Args>(args)...)); | 687 std::forward<Args>(args)...); |
jdoerrie
2017/04/04 14:14:13
There was some discussion in the emplace thread cl
dyaroshev
2017/04/04 15:48:21
This wasn't the intention (at least from my point
| |
688 } | 688 } |
689 | 689 |
690 // For containers like sets, the key is the same as the value. This implements | 690 // For containers like sets, the key is the same as the value. This implements |
691 // the GetKeyFromValue template parameter to flat_tree for this case. | 691 // the GetKeyFromValue template parameter to flat_tree for this case. |
692 template <class Key> | 692 template <class Key> |
693 struct GetKeyFromValueIdentity { | 693 struct GetKeyFromValueIdentity { |
694 const Key& operator()(const Key& k) const { return k; } | 694 const Key& operator()(const Key& k) const { return k; } |
695 }; | 695 }; |
696 | 696 |
697 } // namespace internal | 697 } // namespace internal |
(...skipping 10 matching lines...) Expand all Loading... | |
708 void EraseIf(base::internal::flat_tree<Key, Value, GetKeyFromValue, KeyCompare>& | 708 void EraseIf(base::internal::flat_tree<Key, Value, GetKeyFromValue, KeyCompare>& |
709 container, | 709 container, |
710 Predicate pred) { | 710 Predicate pred) { |
711 container.erase(std::remove_if(container.begin(), container.end(), pred), | 711 container.erase(std::remove_if(container.begin(), container.end(), pred), |
712 container.end()); | 712 container.end()); |
713 } | 713 } |
714 | 714 |
715 } // namespace base | 715 } // namespace base |
716 | 716 |
717 #endif // BASE_CONTAINERS_FLAT_TREE_H_ | 717 #endif // BASE_CONTAINERS_FLAT_TREE_H_ |
OLD | NEW |