integral_constant type conversion and automatic type for UDL
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
There is currently no conversion between `integral_constant`s of different base types. It would feel more natural if conversions (and cross-type operators?) are supported, similar to those of the underlying integer types.
```
template f (integral_constant);// f(integral_constant{}) would compile
```
It seems to me the compile-time number `N` is the interesting part, rather than the integer width part. Relaxing type constraints generally leads to less verbose code on the users' side, when designing type functions that take or return integral-constants. I assume a common example here would be signed / unsigned conversion for compile-time constant indices.
With cross-type operators and conversions it would also enable designs such as automatic precision for UDL operator""_c. Not that it would make any performance difference at compile time, but when `integral_constant` is used by runtime functions, such as decrypting chars from compile-time encrypted ones, this becomes more convenient than if the type were fixed to `unsigned long long`.
```
integral_constant + 1_c //integral_constant, not sure if it would compile right now
integral_constant<'a'>//c++17 template version, what would the base type be?
```
`integral_constant` plays a rather central role for type traits / transformation because it is the type of all type trait values, and what all their interactions converge to (that is, when we follow the design of trapping compile-time values as long as possible, as opposed to those of `std::integral_constant`).
While experimenting stuff, I implemented a rudimentary `integral_constant` that represents my ideas:
[code](https://gitlab.com/TheWisp/SimpleTemplate/blob/master/integralconstant.h), [tests](https://gitlab.com/TheWisp/SimpleTemplate/blob/master/integralconstanttest.cpp).
Contributor guide
Research direction
Start by reviewing the proposed examples in the issue and the linked prototype files integralconstant.h and integralconstanttest.cpp. Establish the intended scope for cross-type conversions, operators, and UDL behavior before locating the corresponding integral_constant implementation and tests in Boost.Hana. Done means the design is decided and its supported behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100