diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-17 13:37:46 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-17 13:37:46 +0300 |
commit | ac60e6474569a69ffa4b9c28f9ae79ef674c5408 (patch) | |
tree | 8c721e4f9cb58ea03b3b17fe0063f8ba1cdec112 /source/blender/blenlib/tests/BLI_map_test.cc | |
parent | e00a47ffd611b0ab06dba2a4933ab15871d576e6 (diff) |
BLI: provide a default hash for enums
This avoids some boilerplate code that was necessary when using enums
as keys in maps or sets.
Diffstat (limited to 'source/blender/blenlib/tests/BLI_map_test.cc')
-rw-r--r-- | source/blender/blenlib/tests/BLI_map_test.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_map_test.cc b/source/blender/blenlib/tests/BLI_map_test.cc index 323ced87d9e..70c1887a527 100644 --- a/source/blender/blenlib/tests/BLI_map_test.cc +++ b/source/blender/blenlib/tests/BLI_map_test.cc @@ -565,6 +565,28 @@ TEST(map, AddOrModifyExceptions) EXPECT_ANY_THROW({ map.add_or_modify(3, create_fn, modify_fn); }); } +namespace { +enum class TestEnum { + A = 0, + B = 1, + C = 2, + D = 1, +}; +} + +TEST(map, EnumKey) +{ + Map<TestEnum, int> map; + map.add(TestEnum::A, 4); + map.add(TestEnum::B, 6); + EXPECT_EQ(map.lookup(TestEnum::A), 4); + EXPECT_EQ(map.lookup(TestEnum::B), 6); + EXPECT_EQ(map.lookup(TestEnum::D), 6); + EXPECT_FALSE(map.contains(TestEnum::C)); + map.lookup(TestEnum::D) = 10; + EXPECT_EQ(map.lookup(TestEnum::B), 10); +} + /** * Set this to 1 to activate the benchmark. It is disabled by default, because it prints a lot. */ |