diff --git a/sycl/include/sycl/sycl_span.hpp b/sycl/include/sycl/sycl_span.hpp index 84b5b8eeeeba4..a87ea835b0811 100644 --- a/sycl/include/sycl/sycl_span.hpp +++ b/sycl/include/sycl/sycl_span.hpp @@ -217,6 +217,15 @@ template class _SYCL_SPAN_TEMPLATE_VIS span { constexpr span(const span &) noexcept = default; constexpr span &operator=(const span &) noexcept = default; + template + _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span( + element_type (&__arr)[_Sz]) + : __data{__arr} { + (void)_Sz; + _SYCL_SPAN_ASSERT(_Extent == _Sz, + "size mismatch in span's constructor (&_arr)[_Sz]"); + } + _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr} { @@ -609,10 +618,9 @@ as_writable_bytes(span<_Tp, _Extent> __s) noexcept // Deduction guides -// array arg deduction guide. dynamic_extent arg used to select -// the correct template. The _Sz will be used for the __size of the span. +// array arg deduction guide template -span(_Tp (&)[_Sz]) -> span<_Tp, dynamic_extent>; +span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>; template span(std::array<_Tp, _Sz> &) -> span<_Tp, _Sz>; diff --git a/sycl/test/basic_tests/span.cpp b/sycl/test/basic_tests/span.cpp index ae2a13099b8fb..634ed0085227e 100644 --- a/sycl/test/basic_tests/span.cpp +++ b/sycl/test/basic_tests/span.cpp @@ -28,10 +28,18 @@ int main() { sycl::span fromIntVec{vec}; // fully specialized - // TODO: fix fully specialized span from array declaration support - // sycl::span fullSpecArray{arr}; - // sycl::span fullSpecConstArray{constArr}; + sycl::span fullSpecArray{arr}; + sycl::span fullSpecConstArray{constArr}; sycl::span fullSpecVecArray{vec}; + // check that the extent is deduced correctly + static_assert(decltype(fromArray)::extent == decltype(fullSpecArray)::extent, + "extent doesn't match between unspecialized and fully " + "specialized span from array"); + static_assert(decltype(fromConstArray)::extent == + decltype(fullSpecConstArray)::extent, + "extent doesn't match between unspecialized and fully " + "specialized span from const array"); + return 0; -} \ No newline at end of file +}