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 #include "base/containers/flat_map.h" | 5 #include "base/containers/flat_map.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/containers/container_test_utils.h" | 10 #include "base/containers/container_test_utils.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 // The returned mapped reference should refer into the map. | 164 // The returned mapped reference should refer into the map. |
165 s = 22; | 165 s = 22; |
166 EXPECT_EQ(22, m[MoveOnlyInt(1)]); | 166 EXPECT_EQ(22, m[MoveOnlyInt(1)]); |
167 | 167 |
168 // Overwrite existing elements. | 168 // Overwrite existing elements. |
169 m[MoveOnlyInt(1)] = 44; | 169 m[MoveOnlyInt(1)] = 44; |
170 EXPECT_EQ(44, m[MoveOnlyInt(1)]); | 170 EXPECT_EQ(44, m[MoveOnlyInt(1)]); |
171 } | 171 } |
172 | 172 |
| 173 TEST(FlatMap, UniquePtrKeys) { |
| 174 using ExplicitInt = base::MoveOnlyInt; |
| 175 base::flat_map<ExplicitInt, int> m; |
| 176 const auto& m1 = m; |
| 177 int x = 0; |
| 178 m.count(x); |
| 179 m1.count(x); |
| 180 m.find(x); |
| 181 m1.find(x); |
| 182 m.equal_range(x); |
| 183 m1.equal_range(x); |
| 184 m.lower_bound(x); |
| 185 m1.lower_bound(x); |
| 186 m.upper_bound(x); |
| 187 m1.upper_bound(x); |
| 188 m.erase(x); |
| 189 |
| 190 // Check if we broke overload resolution. |
| 191 m.emplace(ExplicitInt(0), 0); |
| 192 m.emplace(ExplicitInt(1), 0); |
| 193 m.erase(m.begin()); |
| 194 m.erase(m.cbegin()); |
| 195 } |
| 196 |
173 } // namespace base | 197 } // namespace base |
OLD | NEW |