OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_CONTAINERS_FLAT_SET_H_ |
| 6 #define BASE_CONTAINERS_FLAT_SET_H_ |
| 7 |
| 8 #include <algorithm> |
| 9 #include <functional> |
| 10 #include <set> |
| 11 #include <utility> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/containers/flat_sorted_container_base.h" |
| 15 #include "base/logging.h" |
| 16 |
| 17 namespace base { |
| 18 |
| 19 namespace internal { |
| 20 |
| 21 template <typename Key, class Compare> |
| 22 struct set_compare : private Compare { |
| 23 using key_type = Key; |
| 24 using value_type = Key; |
| 25 |
| 26 using Compare::operator(); |
| 27 |
| 28 template <typename Lhs, typename Rhs> |
| 29 bool equal(const Lhs& lhs, const Rhs& rhs) { |
| 30 return !operator()(lhs, rhs) && !operator()(rhs, lhs); |
| 31 } |
| 32 |
| 33 const key_type& key_from_value(const value_type& value) { return value; } |
| 34 |
| 35 key_type& key_from_value(value_type& value) { return value; } // NOLINT |
| 36 }; |
| 37 |
| 38 } // namespace internal |
| 39 |
| 40 // std::vector is not particulary friendly with const value type, |
| 41 // so, unlike std::map, we use non const Key |
| 42 template <typename Key, |
| 43 class Compare = std::less<Key>, |
| 44 class UnderlyingType = std::vector<Key>> |
| 45 class flat_set : public internal::flat_sorted_container_base< |
| 46 internal::set_compare<Key, Compare>, |
| 47 UnderlyingType> { |
| 48 using base_type = |
| 49 internal::flat_sorted_container_base<internal::set_compare<Key, Compare>, |
| 50 UnderlyingType>; |
| 51 |
| 52 public: |
| 53 using base_type::base_type; |
| 54 using std_set = std::set<Key>; |
| 55 }; |
| 56 |
| 57 } // namespace base |
| 58 |
| 59 #endif // BASE_CONTAINERS_FLAT_SET_H_ |
OLD | NEW |