Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2019-09-14 17:25:17 +0300
committerJacques Lucke <mail@jlucke.com>2019-09-14 17:25:17 +0300
commit38cc53a168d27b19fb6033a38a043b5076c0aea6 (patch)
treed45fdeb41c60fc2c18420afca2af834b1d56fe21 /tests/gtests
parentd6057b919dca589be97e3b0be15d6e61b04172ea (diff)
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.
Diffstat (limited to 'tests/gtests')
-rw-r--r--tests/gtests/blenlib/BLI_map_test.cc12
1 files changed, 9 insertions, 3 deletions
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));