From 85b7479cb16c0019f76e33cca87fd2a2e95c6a5e Mon Sep 17 00:00:00 2001 From: Fabian Knorr Date: Thu, 3 Aug 2023 14:15:30 +0200 Subject: [PATCH] Remove subscript_result_t workaround --- include/accessor.h | 12 ++++++------ include/fence.h | 2 +- include/ranges.h | 21 +++------------------ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/include/accessor.h b/include/accessor.h index 36c7a24db..e4d26a801 100644 --- a/include/accessor.h +++ b/include/accessor.h @@ -201,8 +201,8 @@ class accessor : public detail::accessor_base return m_device_ptr[get_linear_offset(index)]; } - template - inline std::enable_if_t<(D > 0), detail::subscript_result_t> operator[](const size_t index) const { + template 0), int> = 0> + inline decltype(auto) operator[](const size_t index) const { return detail::subscript(*this, index); } @@ -415,8 +415,8 @@ class accessor : public detail::accessor_b return m_host_ptr[get_linear_offset(index)]; } - template - inline std::enable_if_t<(D > 0), detail::subscript_result_t> operator[](const size_t index) const { + template 0), int> = 0> + inline decltype(auto) operator[](const size_t index) const { return detail::subscript(*this, index); } @@ -666,8 +666,8 @@ class local_accessor { } } - template - inline std::enable_if_t<(D > 0), detail::subscript_result_t> operator[](const size_t dim0) const { + template 0), int> = 0> + inline decltype(auto) operator[](const size_t dim0) const { return detail::subscript(*this, dim0); } diff --git a/include/fence.h b/include/fence.h index 35fc5d831..5c3e48259 100644 --- a/include/fence.h +++ b/include/fence.h @@ -46,7 +46,7 @@ class buffer_snapshot { inline const T& operator[](const id index) const { return m_data[detail::get_linear_index(m_subrange.range, index)]; } template 0), int> = 0> - inline detail::subscript_result_t operator[](const size_t index) const { + inline decltype(auto) operator[](const size_t index) const { return detail::subscript(*this, index); } diff --git a/include/ranges.h b/include/ranges.h index 3b91ad132..1a4ff383a 100644 --- a/include/ranges.h +++ b/include/ranges.h @@ -401,23 +401,8 @@ namespace detail { template class subscript_proxy; - template - struct subscript_result { - using type = subscript_proxy; - }; - - template - struct subscript_result { - using type = decltype(std::declval()[std::declval&>()]); - }; - - // Workaround for old ComputeCpp "stable" compiler: We cannot use decltype(auto), because it will not infer lvalue references correctly - // TODO replace subscript_result and all its uses with decltype(auto) once we require the new ComputeCpp (experimental) compiler. - template - using subscript_result_t = typename subscript_result::type; - template - inline subscript_result_t subscript(Target& tgt, id id, const size_t index) { + inline decltype(auto) subscript(Target& tgt, id id, const size_t index) { static_assert(SubscriptDim < TargetDims); id[SubscriptDim] = index; if constexpr(SubscriptDim == TargetDims - 1) { @@ -428,7 +413,7 @@ namespace detail { } template - inline subscript_result_t subscript(Target& tgt, const size_t index) { + inline decltype(auto) subscript(Target& tgt, const size_t index) { return subscript(tgt, id{}, index); } @@ -437,7 +422,7 @@ namespace detail { public: subscript_proxy(Target& tgt, const id id) : m_tgt(tgt), m_id(id) {} - inline subscript_result_t operator[](const size_t index) const { + inline decltype(auto) operator[](const size_t index) const { return subscript(m_tgt, m_id, index); }