From a8133c7ec28415644bfc6f2f38473bbefc92fe41 Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Mon, 28 Sep 2026 15:21:00 +0200 Subject: [PATCH] Add integral overloads for id and range operators see https://github.com/KhronosGroup/SYCL-Docs/pull/726 fixes https://github.com/KhronosGroup/SYCL-Docs/issues/539 --- include/simsycl/detail/coordinate.hh | 12 +++++++++--- test/ambiguity_tests.cc | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/simsycl/detail/coordinate.hh b/include/simsycl/detail/coordinate.hh index f2ceaff..e3c922d 100644 --- a/include/simsycl/detail/coordinate.hh +++ b/include/simsycl/detail/coordinate.hh @@ -48,7 +48,9 @@ class coordinate { for(int d = 0; d < Dimensions; ++d) { result[d] = lhs.m_values[d] op rhs.m_values[d]; } \ return result; \ } \ - friend constexpr Interface operator op(const Interface &lhs, const size_t &rhs) { \ + template \ + requires(std::integral) \ + friend constexpr Interface operator op(const Interface &lhs, const Integral &rhs) { \ Interface result = make_interface_type(); \ for(int d = 0; d < Dimensions; ++d) { result[d] = lhs.m_values[d] op rhs; } \ return result; \ @@ -78,7 +80,9 @@ class coordinate { for(int d = 0; d < Dimensions; ++d) { lhs.m_values[d] op rhs.m_values[d]; } \ return lhs; \ } \ - friend constexpr Interface &operator op(Interface & lhs, const size_t & rhs) { \ + template \ + requires(std::integral) \ + friend constexpr Interface &operator op(Interface & lhs, const Integral & rhs) { \ for(int d = 0; d < Dimensions; ++d) { lhs.m_values[d] op rhs; } \ return lhs; \ } @@ -97,7 +101,9 @@ class coordinate { #undef SIMSYCL_DETAIL_DEFINE_COORDINATE_BINARY_INPLACE_LHS_OPERATOR #define SIMSYCL_DETAIL_DEFINE_COORDINATE_BINARY_COPY_RHS_OPERATOR(op) \ - friend constexpr Interface operator op(const size_t &lhs, const Interface &rhs) { \ + template \ + requires(std::integral) \ + friend constexpr Interface operator op(const Integral &lhs, const Interface &rhs) { \ Interface result = make_interface_type(); \ for(int d = 0; d < Dimensions; ++d) { result[d] = lhs op rhs.m_values[d]; } \ return result; \ diff --git a/test/ambiguity_tests.cc b/test/ambiguity_tests.cc index 7d7827a..557e2ef 100644 --- a/test/ambiguity_tests.cc +++ b/test/ambiguity_tests.cc @@ -1,5 +1,7 @@ #include +#include + #include using namespace sycl; @@ -27,3 +29,16 @@ TEST_CASE("Calls to the deprecated parallel_for signature are not ambiguous", "[ } SIMSYCL_STOP_IGNORING_DEPRECATIONS + +TEST_CASE("Calls of operator op with integral type are not abiguous", "[ambiguity]") { + SECTION("size_t") { + [[maybe_unused]] auto multiply = [](id<1> i, size_t j) { + return i * j; + }; + } + SECTION("int") { + [[maybe_unused]] auto multiply = [](id<1> i, int j) { + return i * j; + }; + } +}