NVIDIA / NVIDIA/cccl

[BUG]: `static_bounds` and `constant` can't take a floating point in C++17

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

Description

C++17 doesn't allow us to pass floating point types as NTTP, thus this example fails to compile ([link](https://godbolt.org/z/PzW6aYrv7)):
```cpp
#include
#include

int main()
{
[[maybe_unused]] cuda::__argument::__constant<1.f> constant{};
}
```
We could provide a solution that partially works in C++17 by splitting the argument type and values. That means that instead of:
```cpp
template struct constant;
```
we could do:
```cpp
template struct constant;
```
where `V` needn't to have the same type as `T`, thus the user could create a floating point constant from an integral value. For example:
```cpp
constant v;
```
This would also make the framework work for extended floating point types like `__half` of `__nv_bfloat16`

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.