A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/STL/issues/1335 below:

Can we unify overloads and templates? · Issue #1335 · microsoft/STL · GitHub

Related to #189.

<cmath> is one of the STL's most complicated headers (despite the seeming simplicity) because of the "sufficient additional overloads" Standardese in WG21-N4861 [cmath.syn]/2. There's a system of overloads for float and long double (in addition to double provided by the UCRT), and then templates to handle mixed/integral arguments.

There's also some variation - fma and remquo, added in C++11, use a newer technique powered by if constexpr:

template <class _Ty1, class _Ty2, _STD enable_if_t<_STD is_arithmetic_v<_Ty1> && _STD is_arithmetic_v<_Ty2>, int> = 0> _STD _Common_float_type_t<_Ty1, _Ty2> remquo(_Ty1 _Left, _Ty2 _Right, int* _Pquo) noexcept /* strengthened */ { using _Common = _STD _Common_float_type_t<_Ty1, _Ty2>; #if _HAS_IF_CONSTEXPR if constexpr (_STD is_same_v<_Common, float>) { return _CSTD remquof(static_cast<_Common>(_Left), static_cast<_Common>(_Right), _Pquo); } else if constexpr (_STD is_same_v<_Common, double>) { return _CSTD remquo(static_cast<_Common>(_Left), static_cast<_Common>(_Right), _Pquo); } else { return _CSTD remquol(static_cast<_Common>(_Left), static_cast<_Common>(_Right), _Pquo); } #else // ^^^ use "if constexpr" dispatch / use overload resolution vvv return _Remquo(static_cast<_Common>(_Left), static_cast<_Common>(_Right), _Pquo); #endif // _HAS_IF_CONSTEXPR }

(I suspect that

float, float

arguments are always handled by the separate overload, so there is currently no way to activate it for the template.)

Due to [namespace.std]/6 forbidding forming pointers/references to Standard Library functions (except for "addressable functions"), I believe it may now be unobservable whether the float and long double overloads exist separately. If that's the case, now that if constexpr is available for unconditional use, we should consider eliminating the separate overloads and centralizing everything in remquo-style templates.

Again, due to the complexity, changing anything here is relatively high-risk, but it's not impossible.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4