132 #include <type_traits>
135 #define _SYCL_SPAN_TEMPLATE_VIS
136 #define _SYCL_SPAN_INLINE_VISIBILITY inline
139 inline namespace _V1 {
142 using byte =
unsigned char;
146 #if defined(__SYCL_DEVICE_ONLY__)
147 #define _SYCL_SPAN_ASSERT(x, m) ((void)0)
149 #define _SYCL_SPAN_ASSERT(x, m) assert(((x) && m))
153 template <
typename _Tp,
size_t _Extent = dynamic_extent>
class span;
157 template <
class _Tp,
size_t _Extent>
165 template <
class _Tp,
size_t _Sz>
171 template <
class _Tp,
class _ElementType,
class =
void>
174 template <
class _Tp,
class _ElementType>
179 typename std::enable_if<!__is_span<_Tp>::value, std::nullptr_t>::type,
181 typename std::enable_if<!__is_std_array<_Tp>::value,
182 std::nullptr_t>::type,
184 typename std::enable_if<!std::is_array_v<_Tp>, std::nullptr_t>::type,
186 decltype(data(std::declval<_Tp>())),
187 decltype(size(std::declval<_Tp>())),
190 typename std::enable_if<
191 std::is_convertible_v<std::remove_pointer_t<decltype(data(
192 std::declval<_Tp &>()))> (*)[],
194 std::nullptr_t>::type>> :
public std::true_type {};
213 template <
size_t _Sz = _Extent,
214 std::enable_if_t<_Sz == 0, std::nullptr_t> =
nullptr>
220 template <
size_t _Sz = _Extent>
226 "size mismatch in span's constructor (&_arr)[_Sz]");
234 "size mismatch in span's constructor (ptr, len)");
240 "size mismatch in span's constructor (ptr, ptr)");
243 template <
class _OtherElementType,
244 std::enable_if_t<std::is_convertible_v<_OtherElementType (*)[],
246 std::nullptr_t> =
nullptr>
248 std::array<_OtherElementType, _Extent> &__arr)
noexcept
249 : __data{__arr.data()} {}
252 class _OtherElementType,
253 std::enable_if_t<std::is_convertible_v<
const _OtherElementType (*)[],
255 std::nullptr_t> =
nullptr>
257 const std::array<_OtherElementType, _Extent> &__arr)
noexcept
258 : __data{__arr.data()} {}
260 template <
class _Container>
264 std::nullptr_t> =
nullptr)
265 : __data{
std::data(__c)} {
267 "size mismatch in span's constructor (range)");
270 template <
class _Container>
272 const _Container &__c,
275 std::nullptr_t> =
nullptr)
276 : __data{
std::data(__c)} {
278 "size mismatch in span's constructor (range)");
281 template <
class _OtherElementType>
285 std::is_convertible_v<_OtherElementType (*)[],
element_type (*)[]>,
286 std::nullptr_t> =
nullptr)
287 : __data{__other.data()} {}
291 template <
size_t _Count>
294 static_assert(_Count <= _Extent,
"Count out of range in span::first()");
298 template <
size_t _Count>
301 static_assert(_Count <= _Extent,
"Count out of range in span::last()");
309 "Count out of range in span::first(count)");
310 return {data(), __count};
317 "Count out of range in span::last(count)");
318 return {data() + size() - __count, __count};
321 template <
size_t _Offset,
size_t _Count = dynamic_extent>
325 static_assert(_Offset <= _Extent,
"Offset out of range in span::subspan()");
326 static_assert(_Count ==
dynamic_extent || _Count <= _Extent - _Offset,
327 "Offset + count out of range in span::subspan()");
332 return _ReturnType{data() + _Offset,
341 "Offset out of range in span::subspan(offset, count)");
343 "Count out of range in span::subspan(offset, count)");
345 return {data() + __offset, size() - __offset};
347 __count <= size() - __offset,
348 "Offset + count out of range in span::subspan(offset, count)");
349 return {data() + __offset, __count};
365 return __data[__idx];
375 return __data[size() - 1];
399 reinterpret_cast<const byte *
>(data()), size_bytes()};
405 reinterpret_cast<byte *
>(data()), size_bytes()};
412 template <
typename _Tp>
432 : __data{
nullptr}, __size{0} {}
438 : __data{__ptr}, __size{__count} {}
440 : __data{__f}, __size{static_cast<size_t>(
std::distance(__f, __l))} {}
442 template <
size_t _Sz>
445 : __data{__arr}, __size{_Sz} {}
447 template <
class _OtherElementType,
size_t _Sz,
448 std::enable_if_t<std::is_convertible_v<_OtherElementType (*)[],
450 std::nullptr_t> =
nullptr>
452 std::array<_OtherElementType, _Sz> &__arr)
noexcept
453 : __data{__arr.data()}, __size{_Sz} {}
456 class _OtherElementType,
size_t _Sz,
457 std::enable_if_t<std::is_convertible_v<
const _OtherElementType (*)[],
459 std::nullptr_t> =
nullptr>
461 const std::array<_OtherElementType, _Sz> &__arr)
noexcept
462 : __data{__arr.data()}, __size{_Sz} {}
464 template <
class _Container>
468 std::nullptr_t> =
nullptr)
471 template <
class _Container>
473 const _Container &__c,
476 std::nullptr_t> =
nullptr)
479 template <
class _OtherElementType,
size_t _OtherExtent>
483 std::is_convertible_v<_OtherElementType (*)[],
element_type (*)[]>,
485 : __data{__other.
data()}, __size{__other.
size()} {}
489 template <
size_t _Count>
496 template <
size_t _Count>
507 "Count out of range in span::first(count)");
508 return {data(), __count};
515 "Count out of range in span::last(count)");
516 return {data() + size() - __count, __count};
519 template <
size_t _Offset,
size_t _Count = dynamic_extent>
523 "Offset out of range in span::subspan()");
525 "Offset + count out of range in span::subspan()");
527 data() + _Offset, _Count ==
dynamic_extent ? size() - _Offset : _Count};
534 "Offset out of range in span::subspan(offset, count)");
536 "count out of range in span::subspan(offset, count)");
538 return {data() + __offset, size() - __offset};
540 __count <= size() - __offset,
541 "Offset + count out of range in span::subspan(offset, count)");
542 return {data() + __offset, __count};
558 return __data[__idx];
568 return __data[size() - 1];
591 return {
reinterpret_cast<const byte *
>(data()), size_bytes()};
596 return {
reinterpret_cast<byte *
>(data()), size_bytes()};
605 template <
class _Tp,
size_t _Extent>
607 -> decltype(__s.__as_bytes()) {
608 return __s.__as_bytes();
611 template <
class _Tp,
size_t _Extent>
614 -> std::enable_if_t<!std::is_const_v<_Tp>,
615 decltype(__s.__as_writable_bytes())> {
616 return __s.__as_writable_bytes();
622 template <
class _Tp,
size_t _Sz>
627 template <
class _Tp,
size_t _Sz>
630 template <
class _Container>
633 template <
class _Container>
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, _Count > last() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const span< _OtherElementType, _OtherExtent > &__other, std::enable_if_t< std::is_convertible_v< _OtherElementType(*)[], element_type(*)[]>, std::nullptr_t >=nullptr) noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const std::array< _OtherElementType, _Sz > &__arr) noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference front() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(std::array< _OtherElementType, _Sz > &__arr) noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const _Container &__c, std::enable_if_t< __is_span_compatible_container< const _Container, _Tp >::value, std::nullptr_t >=nullptr)
constexpr span(const span &) noexcept=default
std::reverse_iterator< pointer > rev_iterator
constexpr span & operator=(const span &) noexcept=default
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, dynamic_extent > first(size_type __count) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(pointer __ptr, size_type __count)
_SYCL_SPAN_INLINE_VISIBILITY span< const byte, dynamic_extent > __as_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY size_type size_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference operator[](size_type __idx) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY pointer data() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY iterator begin() const noexcept
const _Tp * const_pointer
const _Tp & const_reference
constexpr _SYCL_SPAN_INLINE_VISIBILITY iterator end() const noexcept
constexpr span< element_type, dynamic_extent > _SYCL_SPAN_INLINE_VISIBILITY subspan(size_type __offset, size_type __count=dynamic_extent) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, dynamic_extent > last(size_type __count) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY size_type size() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, _Count > first() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY bool empty() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY rev_iterator rbegin() const noexcept
ptrdiff_t difference_type
std::remove_cv_t< _Tp > value_type
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(_Container &__c, std::enable_if_t< __is_span_compatible_container< _Container, _Tp >::value, std::nullptr_t >=nullptr)
constexpr _SYCL_SPAN_INLINE_VISIBILITY rev_iterator rend() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(pointer __f, pointer __l)
constexpr _SYCL_SPAN_INLINE_VISIBILITY span() noexcept
_SYCL_SPAN_INLINE_VISIBILITY span< byte, dynamic_extent > __as_writable_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference back() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(element_type(&__arr)[_Sz]) noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, _Count > subspan() const noexcept
const _Tp * const_pointer
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference front() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span() noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY bool empty() const noexcept
const _Tp & const_reference
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const span< _OtherElementType, _Extent > &__other, std::enable_if_t< std::is_convertible_v< _OtherElementType(*)[], element_type(*)[]>, std::nullptr_t >=nullptr)
constexpr _SYCL_SPAN_INLINE_VISIBILITY iterator end() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY size_type size() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY pointer data() const noexcept
constexpr span & operator=(const span &) noexcept=default
constexpr span(const span &) noexcept=default
_SYCL_SPAN_INLINE_VISIBILITY span< byte, _Extent *sizeof(element_type)> __as_writable_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY size_type size_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference operator[](size_type __idx) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY rev_iterator rend() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY reference back() const noexcept
ptrdiff_t difference_type
constexpr _SYCL_SPAN_INLINE_VISIBILITY iterator begin() const noexcept
_SYCL_SPAN_INLINE_VISIBILITY span< const byte, _Extent *sizeof(element_type)> __as_bytes() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(pointer __ptr, size_type __count)
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, dynamic_extent > last(size_type __count) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, dynamic_extent > first(size_type __count) const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, dynamic_extent > subspan(size_type __offset, size_type __count=dynamic_extent) const noexcept
std::reverse_iterator< pointer > rev_iterator
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(pointer __f, pointer __l)
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const _Container &__c, std::enable_if_t< __is_span_compatible_container< const _Container, _Tp >::value, std::nullptr_t >=nullptr)
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(_Container &__c, std::enable_if_t< __is_span_compatible_container< _Container, _Tp >::value, std::nullptr_t >=nullptr)
std::remove_cv_t< _Tp > value_type
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(element_type(&__arr)[_Sz])
constexpr _SYCL_SPAN_INLINE_VISIBILITY auto subspan() const noexcept -> span< element_type,(_Count !=dynamic_extent ? _Count :_Extent - _Offset)>
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(std::array< _OtherElementType, _Extent > &__arr) noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY rev_iterator rbegin() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, _Count > last() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span< element_type, _Count > first() const noexcept
constexpr _SYCL_SPAN_INLINE_VISIBILITY span(const std::array< _OtherElementType, _Extent > &__arr) noexcept
sycl::ext::oneapi::experimental::annotated_ref< T, property_list_t > reference
_SYCL_SPAN_INLINE_VISIBILITY auto as_writable_bytes(span< _Tp, _Extent > __s) noexcept -> std::enable_if_t<!std::is_const_v< _Tp >, decltype(__s.__as_writable_bytes())>
std::conditional_t< is_decorated, decorated_type *, std::add_pointer_t< value_type > > pointer
span(_Tp(&)[_Sz]) -> span< _Tp, _Sz >
constexpr size_t dynamic_extent
_SYCL_SPAN_INLINE_VISIBILITY auto as_bytes(span< _Tp, _Extent > __s) noexcept -> decltype(__s.__as_bytes())
_Abi const simd< _Tp, _Abi > & noexcept
#define _SYCL_SPAN_INLINE_VISIBILITY
#define _SYCL_SPAN_ASSERT(x, m)
#define _SYCL_SPAN_TEMPLATE_VIS