boostorg / boostorg/safe_numerics
Consider enabling CTAD for the safe type
- Dominant language
- C++
- Stars
- 222
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
CTAD: class template argument deduction
Such thing will allow this use case, in C++20 and higher.
```cpp
#include
void uncontrolled(double*, int); // true external function
using boost::safe_numerics::safe;
int main() {
std::vector v = {1.0, 2.0, 3.0};
uncontrolled(v.data(), safe{v.max_size()}); // ok, throws
// uncontrolled(v.data(), safe{v.max_size()}); // needs CTAD
}
```
complete code: https://godbolt.org/z/s8bYz9rqb
The most basic code for this feature could be:
```cpp
#if define(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201703L)
namespace boost::safe_numerics {
template safe_base(In) -> safe_base;
}
#endif
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with boost/safe_numerics/safe_integer.hpp and the safe type used in the provided C++20 example. Check how the existing safe template is declared and how the proposed deduction guide would apply. Done means the safe{v.max_size()} form compiles and provides the expected safe integer type under the supported deduction-guide feature test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100