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) { | |
danakj
2017/06/26 19:33:12
nit: there's no UniquePtrs in this test, CompareWi
dyaroshev
2017/06/26 22:40:42
Done
| |
174 using ExplicitInt = base::MoveOnlyInt; | |
175 base::flat_map<ExplicitInt, int> m; | |
176 const auto& m1 = m; | |
177 int x = 0; | |
178 | |
179 // Check if we can use lookup functions without converting to key_type. | |
180 // Correctness is checked in flat_tree tests. | |
181 m.count(x); | |
182 m1.count(x); | |
183 m.find(x); | |
184 m1.find(x); | |
185 m.equal_range(x); | |
186 m1.equal_range(x); | |
187 m.lower_bound(x); | |
188 m1.lower_bound(x); | |
189 m.upper_bound(x); | |
190 m1.upper_bound(x); | |
191 m.erase(x); | |
192 | |
193 // Check if we broke overload resolution. | |
194 m.emplace(ExplicitInt(0), 0); | |
195 m.emplace(ExplicitInt(1), 0); | |
196 m.erase(m.begin()); | |
197 m.erase(m.cbegin()); | |
198 } | |
199 | |
173 } // namespace base | 200 } // namespace base |
OLD | NEW |