Skip to content

Commit acc0bee

Browse files
committed
add operator[]
1 parent 33a2557 commit acc0bee

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

sycl/include/sycl/ext/oneapi/annotated_arg/annotated_arg.hpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,14 @@ namespace oneapi {
5454
namespace experimental {
5555

5656
namespace detail {
57-
// Type-trait for checking if a type defines `operator->`.
58-
template <typename T, typename = void>
59-
struct HasParenthesisOperator : std::false_type {};
60-
template <typename T>
61-
struct HasParenthesisOperator<
62-
T, sycl::detail::void_t<decltype(std::declval<T>().operator()())>>
63-
: std::true_type {};
6457

58+
// Type-trait for checking if a type defines `operator[]`.
6559
template <typename T, typename = void>
6660
struct HasSubscriptOperator : std::false_type {};
6761

6862
template <typename T>
6963
struct HasSubscriptOperator<
70-
T, sycl::detail::void_t<decltype(std::declval<T>().operator[]())>>
64+
T, typename std::enable_if_t<!std::is_void<decltype(std::declval<T>().operator[](0))>::value>>
7165
: std::true_type {};
7266

7367
} // namespace detail
@@ -274,13 +268,21 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(annotated_arg) annotated_arg <T, detail::
274268
return obj;
275269
}
276270

277-
// template<typename... Args>
278-
// template <class RelayT = T>
279-
// std::enable_if_t<detail::HasParenthesisOperator<RelayT>::value>
280-
// &operator()(Args... args) noexcept {
281-
// __SYCL_HOST_NOT_SUPPORTED("operator() on an annotated_arg")
282-
// return obj.operator(args);
283-
// }
271+
template <class RelayT = T>
272+
std::enable_if_t<
273+
detail::HasSubscriptOperator<RelayT>::value,
274+
const decltype(std::declval<RelayT>().operator[](0))>
275+
&operator[](std::ptrdiff_t idx) const noexcept {
276+
return obj.operator[](idx);
277+
}
278+
279+
template <class RelayT = T>
280+
std::enable_if_t<
281+
detail::HasSubscriptOperator<RelayT>::value,
282+
decltype(std::declval<RelayT>().operator[](0))>
283+
&operator[](std::ptrdiff_t idx) noexcept {
284+
return obj.operator[](idx);
285+
}
284286

285287
template <typename PropertyT> static constexpr bool has_property() {
286288
return property_list_t::template has_property<PropertyT>();

0 commit comments

Comments
 (0)