-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Currently, <numeric> includes <limits> in C++20 mode:
Lines 13 to 15 in 46ae5f8
| #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:
Lines 640 to 641 in 46ae5f8
| if constexpr (is_floating_point_v<_Ty>) { | |
| constexpr _Ty _High_limit = (numeric_limits<_Ty>::max)() / 2; |
Line 675 in 46ae5f8
| constexpr _Ty _Low_limit = (numeric_limits<_Ty>::min)() * 2; |
<numeric> always includes <xutility> which includes <climits>:
Line 11 in 46ae5f8
| #include <xutility> |
Line 12 in 46ae5f8
| #include <climits> |
So <numeric> could directly use the classic macros:
Lines 872 to 878 in 46ae5f8
| _NODISCARD static constexpr float(min)() noexcept { | |
| return FLT_MIN; | |
| } | |
| _NODISCARD static constexpr float(max)() noexcept { | |
| return FLT_MAX; | |
| } |
Lines 921 to 927 in 46ae5f8
| _NODISCARD static constexpr double(min)() noexcept { | |
| return DBL_MIN; | |
| } | |
| _NODISCARD static constexpr double(max)() noexcept { | |
| return DBL_MAX; | |
| } |
Lines 970 to 976 in 46ae5f8
| _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 forfloat,double, andlong double. - Similarly define
_Floating_max<_Ty>. - Replace the
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:
Lines 108 to 118 in 46ae5f8
| 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 | |
| }; |