Skip to content

Commit

Permalink
Remove subscript_result_t workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Aug 7, 2023
1 parent e1642f2 commit 85b7479
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
12 changes: 6 additions & 6 deletions include/accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class accessor<DataT, Dims, Mode, target::device> : public detail::accessor_base
return m_device_ptr[get_linear_offset(index)];
}

template <int D = Dims>
inline std::enable_if_t<(D > 0), detail::subscript_result_t<D, const accessor>> operator[](const size_t index) const {
template <int D = Dims, std::enable_if_t<(D > 0), int> = 0>
inline decltype(auto) operator[](const size_t index) const {
return detail::subscript<D>(*this, index);
}

Expand Down Expand Up @@ -415,8 +415,8 @@ class accessor<DataT, Dims, Mode, target::host_task> : public detail::accessor_b
return m_host_ptr[get_linear_offset(index)];
}

template <int D = Dims>
inline std::enable_if_t<(D > 0), detail::subscript_result_t<D, const accessor>> operator[](const size_t index) const {
template <int D = Dims, std::enable_if_t<(D > 0), int> = 0>
inline decltype(auto) operator[](const size_t index) const {
return detail::subscript<D>(*this, index);
}

Expand Down Expand Up @@ -666,8 +666,8 @@ class local_accessor {
}
}

template <int D = Dims>
inline std::enable_if_t<(D > 0), detail::subscript_result_t<Dims, const local_accessor>> operator[](const size_t dim0) const {
template <int D = Dims, std::enable_if_t<(D > 0), int> = 0>
inline decltype(auto) operator[](const size_t dim0) const {
return detail::subscript<Dims>(*this, dim0);
}

Expand Down
2 changes: 1 addition & 1 deletion include/fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class buffer_snapshot {
inline const T& operator[](const id<Dims> index) const { return m_data[detail::get_linear_index(m_subrange.range, index)]; }

template <int D = Dims, std::enable_if_t<(D > 0), int> = 0>
inline detail::subscript_result_t<Dims, const buffer_snapshot> operator[](const size_t index) const {
inline decltype(auto) operator[](const size_t index) const {
return detail::subscript<Dims>(*this, index);
}

Expand Down
21 changes: 3 additions & 18 deletions include/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,8 @@ namespace detail {
template <int TargetDims, typename Target, int SubscriptDim = 0>
class subscript_proxy;

template <int TargetDims, typename Target, int SubscriptDim = 0>
struct subscript_result {
using type = subscript_proxy<TargetDims, Target, SubscriptDim + 1>;
};

template <int TargetDims, typename Target>
struct subscript_result<TargetDims, Target, TargetDims - 1> {
using type = decltype(std::declval<Target&>()[std::declval<const id<TargetDims>&>()]);
};

// 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 <int TargetDims, typename Target, int SubscriptDim = 0>
using subscript_result_t = typename subscript_result<TargetDims, Target, SubscriptDim>::type;

template <int TargetDims, typename Target, int SubscriptDim>
inline subscript_result_t<TargetDims, Target, SubscriptDim> subscript(Target& tgt, id<TargetDims> id, const size_t index) {
inline decltype(auto) subscript(Target& tgt, id<TargetDims> id, const size_t index) {
static_assert(SubscriptDim < TargetDims);
id[SubscriptDim] = index;
if constexpr(SubscriptDim == TargetDims - 1) {
Expand All @@ -428,7 +413,7 @@ namespace detail {
}

template <int TargetDims, typename Target>
inline subscript_result_t<TargetDims, Target> subscript(Target& tgt, const size_t index) {
inline decltype(auto) subscript(Target& tgt, const size_t index) {
return subscript<TargetDims, Target, 0>(tgt, id<TargetDims>{}, index);
}

Expand All @@ -437,7 +422,7 @@ namespace detail {
public:
subscript_proxy(Target& tgt, const id<TargetDims> id) : m_tgt(tgt), m_id(id) {}

inline subscript_result_t<TargetDims, Target, SubscriptDim> operator[](const size_t index) const {
inline decltype(auto) operator[](const size_t index) const {
return subscript<TargetDims, Target, SubscriptDim>(m_tgt, m_id, index);
}

Expand Down

0 comments on commit 85b7479

Please sign in to comment.