NVIDIA / NVIDIA/cccl

[BUG]: `constant_sequence` can't take an array in C++17

Open
#9,272 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

Compared to C++20, the set of types that can be passed as NTTP in C++17 is fairly limited. The problem is that `cuda::__argument::__constant_sequence` takes a single `auto V` NTTP and expects the user to pass the array wrapped by `cuda::std::array`. For example:
```cpp
#include
#include

int main()
{
[[maybe_unused]] cuda::__argument::__constant_sequence const_seq{};
}
```
fails to compile in C++17, see [link](https://godbolt.org/z/rPfKc5eqz).

If we want to make this work, we need to change the type to take the sequence as a variadic NTTP. To simplify the construction, we can add helper factory functions like:
```cpp
template struct constant_sequence { ... };

template
auto make_constant_sequence()
{
// instantiate constant_sequence with elements from _Array and return
}

int main()
{
constexpr int array[]{...};
auto const_seq = make_constant_sequence();
}
```

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.