Currently, <numeric> includes <limits> in C++20 mode:
|
#if _HAS_CXX20
|
|
#include <limits>
|
|
#endif // _HAS_CXX20
|
<limits> is a relatively large header (potentially affecting compiler throughput, i.e. slowing down builds), but our usage is very limited here - we just need floating-point min/max:
|
if constexpr (is_floating_point_v<_Ty>) {
|
|
constexpr _Ty _High_limit = (numeric_limits<_Ty>::max)() / 2;
|
|
constexpr _Ty _Low_limit = (numeric_limits<_Ty>::min)() * 2;
|
<numeric> always includes <xutility> which includes <climits>:
So <numeric> could directly use the classic macros:
|
_NODISCARD static constexpr float(min)() noexcept {
|
|
return FLT_MIN;
|
|
}
|
|
|
|
_NODISCARD static constexpr float(max)() noexcept {
|
|
return FLT_MAX;
|
|
}
|
|
_NODISCARD static constexpr double(min)() noexcept {
|
|
return DBL_MIN;
|
|
}
|
|
|
|
_NODISCARD static constexpr double(max)() noexcept {
|
|
return DBL_MAX;
|
|
}
|
|
_NODISCARD static constexpr long double(min)() noexcept {
|
|
return LDBL_MIN;
|
|
}
|
|
|
|
_NODISCARD static constexpr long double(max)() noexcept {
|
|
return LDBL_MAX;
|
|
}
|
Specifically, the changes in <numeric> I'm envisioning are:
- Stop including
<limits>.
- Define a helper variable template
_Floating_min<_Ty>, specialized for float, double, and long double.
- Similarly define
_Floating_max<_Ty>.
- Replace the
numeric_limits calls with uses of the variable templates. Note that because users could theoretically pass volatile values, the uses should say remove_cv_t<_Ty>; numeric_limits was previously handling that:
|
template <class _Ty>
|
|
class numeric_limits<const _Ty> : public numeric_limits<_Ty> { // numeric limits for const types
|
|
};
|
|
|
|
template <class _Ty>
|
|
class numeric_limits<volatile _Ty> : public numeric_limits<_Ty> { // numeric limits for volatile types
|
|
};
|
|
|
|
template <class _Ty>
|
|
class numeric_limits<const volatile _Ty> : public numeric_limits<_Ty> { // numeric limits for const volatile types
|
|
};
|
Currently,
<numeric>includes<limits>in C++20 mode:STL/stl/inc/numeric
Lines 13 to 15 in 46ae5f8
<limits>is a relatively large header (potentially affecting compiler throughput, i.e. slowing down builds), but our usage is very limited here - we just need floating-point min/max:STL/stl/inc/numeric
Lines 640 to 641 in 46ae5f8
STL/stl/inc/numeric
Line 675 in 46ae5f8
<numeric>always includes<xutility>which includes<climits>:STL/stl/inc/numeric
Line 11 in 46ae5f8
STL/stl/inc/xutility
Line 12 in 46ae5f8
So
<numeric>could directly use the classic macros:STL/stl/inc/limits
Lines 872 to 878 in 46ae5f8
STL/stl/inc/limits
Lines 921 to 927 in 46ae5f8
STL/stl/inc/limits
Lines 970 to 976 in 46ae5f8
Specifically, the changes in
<numeric>I'm envisioning are:<limits>._Floating_min<_Ty>, specialized forfloat,double, andlong double._Floating_max<_Ty>.numeric_limitscalls with uses of the variable templates. Note that because users could theoretically passvolatilevalues, the uses should sayremove_cv_t<_Ty>;numeric_limitswas previously handling that:STL/stl/inc/limits
Lines 108 to 118 in 46ae5f8