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

Fix get_keys of empty hymap #1728

Merged
merged 2 commits into from
Aug 4, 2022
Merged
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
1 change: 1 addition & 0 deletions include/gridtools/common/hymap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ namespace gridtools {
template <>
struct keys<>::values<> {
friend values tuple_getter(values const &) { return {}; }
friend keys hymap_get_keys(values const &) { return {}; }
};

template <class HyMap>
Expand Down
28 changes: 27 additions & 1 deletion tests/unit_tests/common/test_hymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <gtest/gtest.h>

#include <gridtools/common/integral_constant.hpp>
#include <gridtools/common/tuple_util.hpp>
#include <gridtools/meta.hpp>

Expand All @@ -32,6 +33,13 @@ namespace gridtools {
static_assert(is_hymap<hymap::keys<a>::values<int>>::value);
static_assert(is_hymap<hymap::keys<a, b>::values<int, double>>::value);

static_assert(std::is_same_v<get_keys<std::array<int, 2>>,
meta::list<integral_constant<int, 0>, integral_constant<int, 1>>>);
static_assert(std::is_same_v<get_keys<tuple<int, double>>,
meta::list<integral_constant<int, 0>, integral_constant<int, 1>>>);
static_assert(std::is_same_v<get_keys<hymap::keys<>::values<>>, hymap::keys<>>);
static_assert(std::is_same_v<get_keys<hymap::keys<a>::values<int>>, hymap::keys<a>>);

TEST(tuple_like, smoke) {
using testee_t = hymap::keys<a, b, c>::values<int, double, void *>;

Expand Down Expand Up @@ -188,7 +196,25 @@ namespace gridtools {
EXPECT_EQ(16, at_key<c>(testee));
}

TEST(assingment, smoke) {
TEST(concat, smoke) {
auto m1 = hymap::keys<a, b>::make_values(1, 2);
auto m2 = hymap::keys<c>::make_values(3.5);
auto testee = hymap::concat(m1, m2);

EXPECT_EQ(1, at_key<a>(testee));
EXPECT_EQ(2, at_key<b>(testee));
EXPECT_EQ(3.5, at_key<c>(testee));
}

TEST(concat, empty) {
auto m1 = hymap::keys<>::make_values();
auto m2 = hymap::keys<a>::make_values(42);
auto testee = hymap::concat(m1, m2);

EXPECT_EQ(42, at_key<a>(testee));
}

TEST(assignment, smoke) {
hymap::keys<a, b>::values<double, double> testee;
auto src = hymap::keys<b, a, c>::make_values(88, 3.5, 16);
testee = src;
Expand Down