Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for [](value_type &){} local map lambdas. #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/ygm/container/detail/map_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,14 @@ class map_impl {
for (std::pair<const key_type, value_type> &kv : m_local_map) {
fn(kv.first, kv.second);
}
} else if constexpr (std::is_invocable<decltype(fn), value_type &>()) {
for (std::pair<const key_type, value_type> &kv : m_local_map) {
fn(kv.second);
}
} else {
static_assert(ygm::detail::always_false<>,
"local map lambda signature must be invocable with (const "
"&key_type, value_type&) signature");
"key_type &, value_type &) or (value_type &) signatures");
}
}

Expand Down
25 changes: 24 additions & 1 deletion test/test_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ int main(int argc, char **argv) {
}

//
// Test for_all
// Test for_all (key-value)
{
ygm::container::map<std::string, std::string> smap1(world);
ygm::container::map<std::string, std::string> smap2(world);
Expand All @@ -242,5 +242,28 @@ int main(int argc, char **argv) {
ASSERT_RELEASE(smap2.count("red") == 1);
}

//
// Test for_all (value)
{
ygm::container::map<std::string, std::string> smap1(world);
ygm::container::map<std::string, std::string> smap2(world);

smap1.async_insert("dog", "cat");
smap1.async_insert("apple", "orange");
smap1.async_insert("red", "green");

smap1.for_all(
[&smap2](const auto &value) { smap2.async_insert(value, value); });

smap1.comm().barrier();

ASSERT_RELEASE(smap2.count("cat") == 1);
ASSERT_RELEASE(smap2.count("orange") == 1);
ASSERT_RELEASE(smap2.count("green") == 1);
ASSERT_RELEASE(smap2.count("dog") == 0);
ASSERT_RELEASE(smap2.count("apple") == 0);
ASSERT_RELEASE(smap2.count("red") == 0);
}

return 0;
}