Chromium Code Reviews| Index: base/containers/flat_map_unittest.cc |
| diff --git a/base/containers/flat_map_unittest.cc b/base/containers/flat_map_unittest.cc |
| index 0556527635a69ebe16153cd33134fdefc8e96fe6..3ab9a45ddf41113144adfa0841df6a7b4d723237 100644 |
| --- a/base/containers/flat_map_unittest.cc |
| +++ b/base/containers/flat_map_unittest.cc |
| @@ -7,8 +7,8 @@ |
| #include <string> |
| #include <vector> |
| -#include "base/containers/container_test_utils.h" |
| #include "base/macros.h" |
| +#include "base/test/move_only_int.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -170,4 +170,44 @@ TEST(FlatMap, SubscriptMoveOnlyKey) { |
| EXPECT_EQ(44, m[MoveOnlyInt(1)]); |
| } |
| +TEST(FlatMap, UsingTransparentCompare) { |
| + using ExplicitInt = base::MoveOnlyInt; |
| + base::flat_map<ExplicitInt, int> m; |
| + const auto& m1 = m; |
| + int x = 0; |
| + |
| + // Check if we can use lookup functions without converting to key_type. |
| + // Correctness is checked in flat_tree tests. |
| + m.count(x); |
| + m1.count(x); |
| + m.find(x); |
| + m1.find(x); |
| + m.equal_range(x); |
| + m1.equal_range(x); |
| + m.lower_bound(x); |
| + m1.lower_bound(x); |
| + m.upper_bound(x); |
| + m1.upper_bound(x); |
| + m.erase(x); |
| + |
| + // Check if we broke overload resolution. |
| + m.emplace(ExplicitInt(0), 0); |
| + m.emplace(ExplicitInt(1), 0); |
| + m.erase(m.begin()); |
| + m.erase(m.cbegin()); |
| +} |
| + |
| +TEST(FlatMap, Examples) { |
| + base::flat_map<std::string, int> str_to_int({{"a", 1}, {"c", 2}, {"b", 2}}, |
| + base::KEEP_FIRST_OF_DUPES); |
| + |
| + // NOTE: does construct a temporary string. |
| + str_to_int["c"] = 3; |
| + |
| + // Do not construct temporary strings. |
|
danakj
2017/06/27 23:48:25
If we're not testing somehow the temp strings are
dyaroshev
2017/06/28 09:13:59
Done
|
| + str_to_int.lower_bound("abc")->second = 3; |
| + str_to_int.erase("c"); |
| + EXPECT_EQ(str_to_int.end(), str_to_int.find("c")); |
| +} |
| + |
| } // namespace base |