From 3913959d23ba052bb7a118e1d694ecf6dffc5297 Mon Sep 17 00:00:00 2001 From: Felix Thaler Date: Tue, 29 Oct 2024 13:55:23 +0100 Subject: [PATCH] Fix sid::as_const for C arrays --- include/gridtools/sid/as_const.hpp | 4 ++-- tests/unit_tests/sid/test_sid_as_const.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/gridtools/sid/as_const.hpp b/include/gridtools/sid/as_const.hpp index 0e8f1ba8b..88d90cf75 100644 --- a/include/gridtools/sid/as_const.hpp +++ b/include/gridtools/sid/as_const.hpp @@ -51,14 +51,14 @@ namespace gridtools { * probably might we need the `host` and `device` variations as well */ template >, + class Ptr = sid::ptr_type>>, std::enable_if_t && !std::is_const_v>, int> = 0> as_const_impl_::const_adapter as_const(Src &&src) { return {std::forward(src)}; } template >, + class Ptr = sid::ptr_type>>, std::enable_if_t || std::is_const_v>, int> = 0> decltype(auto) as_const(Src &&src) { return std::forward(src); diff --git a/tests/unit_tests/sid/test_sid_as_const.cpp b/tests/unit_tests/sid/test_sid_as_const.cpp index 7f32ebf98..e6af42e0c 100644 --- a/tests/unit_tests/sid/test_sid_as_const.cpp +++ b/tests/unit_tests/sid/test_sid_as_const.cpp @@ -32,5 +32,15 @@ namespace gridtools { static_assert(std::is_same_v, 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()); + static_assert(std::is_same_v, int const *>); + EXPECT_EQ(sid::get_origin(src)(), sid::get_origin(testee)()); + } } // namespace } // namespace gridtools