Skip to content

Commit

Permalink
Fix sid::as_const for C arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fthaler committed Oct 29, 2024
1 parent 5732d10 commit 3913959
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/gridtools/sid/as_const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ namespace gridtools {
* probably might we need the `host` and `device` variations as well
*/
template <class Src,
class Ptr = sid::ptr_type<std::decay_t<Src>>,
class Ptr = sid::ptr_type<std::remove_cv_t<std::remove_reference_t<Src>>>,
std::enable_if_t<std::is_pointer_v<Ptr> && !std::is_const_v<std::remove_pointer_t<Ptr>>, int> = 0>
as_const_impl_::const_adapter<Src> as_const(Src &&src) {
return {std::forward<Src>(src)};
}

template <class Src,
class Ptr = sid::ptr_type<std::decay_t<Src>>,
class Ptr = sid::ptr_type<std::remove_cv_t<std::remove_reference_t<Src>>>,
std::enable_if_t<!std::is_pointer_v<Ptr> || std::is_const_v<std::remove_pointer_t<Ptr>>, int> = 0>
decltype(auto) as_const(Src &&src) {
return std::forward<Src>(src);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/sid/test_sid_as_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,15 @@ namespace gridtools {
static_assert(std::is_same_v<sid::ptr_type<testee_t>, double const *>);
EXPECT_EQ(sid::get_origin(src)(), sid::get_origin(testee)());
}

TEST(as_const, c_array) {
int src[3][2] = {{0, 1}, {10, 11}, {20, 21}};
auto testee = sid::as_const(src);
using testee_t = decltype(testee);

static_assert(is_sid<testee_t>());
static_assert(std::is_same_v<sid::ptr_type<testee_t>, int const *>);
EXPECT_EQ(sid::get_origin(src)(), sid::get_origin(testee)());
}
} // namespace
} // namespace gridtools

0 comments on commit 3913959

Please sign in to comment.