Fix example to reflect new usage of lazy_emplace_l - issue #143

This commit is contained in:
greg7mdp
2022-06-20 19:54:26 -04:00
parent eb60b8ac59
commit 9e87d79404
3 changed files with 7 additions and 4 deletions
+3
View File
@@ -138,6 +138,9 @@ if (PHMAP_BUILD_EXAMPLES)
add_executable(ex_basic examples/basic.cc phmap.natvis)
add_executable(ex_bench examples/bench.cc phmap.natvis)
add_executable(ex_emplace examples/emplace.cc phmap.natvis)
if (MSVC)
add_executable(ex_lazy_emplace_l examples/lazy_emplace_l.cc phmap.natvis)
endif()
add_executable(ex_serialize examples/serialize.cc phmap.natvis)
target_include_directories(ex_serialize PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../cereal/include>)
add_executable(ex_hash_std examples/hash_std.cc phmap.natvis)
+1 -1
View File
@@ -30,7 +30,7 @@ public:
{
int newIndex = -1;
m_stringsMap.lazy_emplace_l(std::move(str),
[&](int& v) { newIndex = v; }, // called only when key was already present
[&](Map::value_type& p) { newIndex = p.second; }, // called only when key was already present
[&](const Map::constructor& ctor) // construct value_type in place when key not present
{ newIndex = InterlockedIncrement(curIdx); ctor(std::move(str), newIndex); });
+3 -3
View File
@@ -3276,10 +3276,10 @@ public:
return false;
}
// if map does not contains key, it is inserted and the mapped value is value-constructed
// with the provided arguments (if any), as with try_emplace.
// if map already contains key, then the lambda is called with the mapped value (under
// if map already contains key, the first lambda is called with the mapped value (under
// write lock protection) and can update the mapped value.
// if map does not contains key, the second lambda is called and it should invoke the
// passed constructor to construct the value
// returns true if key was not already present, false otherwise.
// ---------------------------------------------------------------------------------------
template <class K = key_type, class FExists, class FEmplace>