mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-30 00:50:38 +08:00
issue #60: add non-const if_contains() which can update the mapped_value.
This commit is contained in:
@@ -13,13 +13,18 @@ TEST(THIS_TEST_NAME, ThreadSafeContains) {
|
||||
// We can't test mutable keys, or non-copyable keys with ThisMap.
|
||||
// Test that the nodes have the proper API.
|
||||
ThisMap<int, int> m = { {1, 7}, {2, 9} };
|
||||
auto val = 0;
|
||||
|
||||
auto func = [&val](int& v) { val = v; };
|
||||
EXPECT_TRUE(m.if_contains(2, func));
|
||||
const ThisMap<int, int>& const_m(m);
|
||||
|
||||
auto val = 0;
|
||||
auto get_value = [&val](const int& v) { val = v; };
|
||||
EXPECT_TRUE(const_m.if_contains(2, get_value));
|
||||
EXPECT_EQ(val, 9);
|
||||
|
||||
EXPECT_FALSE(m.if_contains(3, func));
|
||||
EXPECT_FALSE(m.if_contains(3, get_value));
|
||||
|
||||
auto set_value = [&val](int& v) { v = 11; };
|
||||
EXPECT_TRUE(m.if_contains(2, set_value));
|
||||
EXPECT_EQ(m[2], 11);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user