From 38cc53a168d27b19fb6033a38a043b5076c0aea6 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 14 Sep 2019 16:25:17 +0200 Subject: BLI: make Map.add_or_modify more powerful The function now allows custom return types defined by the callbacks. This can be useful when a user of the data structure has to implement some custom behavior. --- tests/gtests/blenlib/BLI_map_test.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/gtests') diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc index 3acb76e09f0..61e7a603d13 100644 --- a/tests/gtests/blenlib/BLI_map_test.cc +++ b/tests/gtests/blenlib/BLI_map_test.cc @@ -180,11 +180,17 @@ TEST(map, LookupOrAdd_Lambdas) EXPECT_EQ(map.lookup_or_add(1, lambda1), 20.0f); } -TEST(map, InsertOrModify) +TEST(map, AddOrModify) { IntFloatMap map; - auto create_func = []() { return 10.0f; }; - auto modify_func = [](float &value) { value += 5; }; + auto create_func = [](float *value) { + *value = 10.0f; + return true; + }; + auto modify_func = [](float *value) { + *value += 5; + return false; + }; EXPECT_TRUE(map.add_or_modify(1, create_func, modify_func)); EXPECT_EQ(map.lookup(1), 10.0f); EXPECT_FALSE(map.add_or_modify(1, create_func, modify_func)); -- cgit v1.2.3