intel / intel/llvm

Update `sycl::span` interface

Open
#12,918 0 comments 0 reactions 0 assignees View on GitHub
confirmed enhancement
Dominant language
LLVM
Stars
1.5k
Forks
854
Avg merge
3d 17h
Merged PRs (30d)
137

Description

### Is your feature request related to a problem? Please describe

The [`sycl::span`](https://github.com/intel/llvm/blob/621cf51759e75eb6f7fb72974e2d2fef29fb41ee/sycl/include/sycl/sycl_span.hpp) headers are supposedly derived from `libcxx` [`std::span` headers](https://github.com/intel/llvm/blob/621cf51759e75eb6f7fb72974e2d2fef29fb41ee/libcxx/include/span). However, both interfaces differ.

Notable differences include constructors, e.g., `std::span` defines:

```c++
template
constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
```

whereas `sycl::span` defines:

```c++
constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type count);
```

Extract of `diff` corresponding to constructors:

```diff
- constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type
-count); constexpr explicit(Extent != dynamic_extent) span(pointer firstElem,
-pointer lastElem); template constexpr span(element_type (&arr)[N])
-noexcept; template constexpr span(array& arr)
-noexcept; template constexpr span(const array& arr)
-noexcept; template constexpr explicit(Extent !=
-dynamic_extent) span(Container& cont); template constexpr
-explicit(Extent != dynamic_extent) span(const Container& cont); constexpr
-span(const span& other) noexcept = default; template constexpr explicit(Extent != dynamic_extent) span(const
-span& s) noexcept; ~span() noexcept = default;
+ template
+ constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
+ template
+ constexpr explicit(Extent != dynamic_extent) span(It first, End last);
+ template
+ constexpr span(type_identity_t (&arr)[N]) noexcept;
+ template
+ constexpr span(array& arr) noexcept;
+ template
+ constexpr span(const array& arr) noexcept;
+ template
+ constexpr explicit(Extent != dynamic_extent) span(R&& r);
+ constexpr explicit(extent != dynamic_extent) span(std::initializer_list il); // Since C++26
+ constexpr span(const span& other) noexcept = default;
+ template
+ constexpr explicit(Extent != dynamic_extent) span(const span& s) noexcept;
```

`sycl::span` headers should be updated to follow the SYCL spec, that states:

> The following features are pre-adopted by SYCL 2020 and made available in the `sycl::` namespace: **`std::span`**, `std::dynamic_extent`, `std::bit_cast`. The implementations of pre-adopted features are compliant with the next C++ specification (_Read: C++ 20_), and are expected to forward directly to standard C++ features in a future version of SYCL.

[`std::span`](https://timsong-cpp.github.io/cppwp/views.span) definition for reference.

### Describe the solution you would like

Update `sycl::span` headers according to the C++ 20 specification.

### Additional context

DPC++ version: 621cf51759e75eb6f7fb72974e2d2fef29fb41ee

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.