From e9f8d353244cb903c9d62ade48122d6bacc5bc0d Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Sat, 27 May 2023 01:24:12 +0200 Subject: [PATCH 1/3] Introduce `_Is_transparent` helper trait Also a concept for future-proofing. --- stl/inc/xhash | 14 ++++++++------ stl/inc/xtree | 32 ++++++++++++++++++-------------- stl/inc/xutility | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/stl/inc/xhash b/stl/inc/xhash index 71460bb5e2..836ed52e21 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -108,12 +108,16 @@ struct _Uhash_choose_transparency { #if _HAS_CXX20 template struct _Uhash_choose_transparency<_Kty, _Hasher, _Keyeq, - void_t> { + enable_if_t, _Is_transparent<_Keyeq>>>> { // transparency selector for transparent hashed containers template using _Deduce_key = const _Keyty&; - using _Transparent = void; + template , + is_convertible<_Kx, typename _Container::iterator>>, + int> = 0> + using _Supports_transparency = void; }; #endif // _HAS_CXX20 @@ -1140,8 +1144,7 @@ public: } #if _HAS_CXX23 - template , is_convertible<_Kx, iterator>>, int> = 0> + template > size_type erase(_Kx&& _Keyval) noexcept(noexcept(_Erase(_Keyval))) /* strengthened */ { return _Erase(_Keyval); } @@ -1380,8 +1383,7 @@ public: } #if _HAS_CXX23 - template , is_convertible<_Kx, iterator>>, int> = 0> + template > node_type extract(_Kx&& _Keyval) { const auto _Ptr = _Extract(_Keyval); if (!_Ptr) { diff --git a/stl/inc/xtree b/stl/inc/xtree index 639185e639..167e168acd 100644 --- a/stl/inc/xtree +++ b/stl/inc/xtree @@ -1344,8 +1344,10 @@ public: } #if _HAS_CXX23 - template , is_convertible<_Kx, iterator>>, int> = 0> + template , + negation, is_convertible<_Kx, iterator>>>>, + int> = 0> size_type erase(_Kx&& _Keyval) noexcept(noexcept(_Eqrange(_Keyval))) /* strengthened */ { return _Erase(_Eqrange(_Keyval)); } @@ -1382,12 +1384,12 @@ public: return const_iterator(_Find(_Keyval), _Get_scary()); } - template + template , int> = 0> _NODISCARD iterator find(const _Other& _Keyval) { return iterator(_Find(_Keyval), _Get_scary()); } - template + template , int> = 0> _NODISCARD const_iterator find(const _Other& _Keyval) const { return const_iterator(_Find(_Keyval), _Get_scary()); } @@ -1397,7 +1399,7 @@ public: return _Lower_bound_duplicate(_Find_lower_bound(_Keyval)._Bound, _Keyval); } - template + template , int> = 0> _NODISCARD bool contains(const _Other& _Keyval) const { return _Lower_bound_duplicate(_Find_lower_bound(_Keyval)._Bound, _Keyval); } @@ -1413,7 +1415,7 @@ public: } } - template + template , int> = 0> _NODISCARD size_type count(const _Other& _Keyval) const { const auto _Ans = _Eqrange(_Keyval); return static_cast(_STD distance( @@ -1428,12 +1430,12 @@ public: return const_iterator(_Find_lower_bound(_Keyval)._Bound, _Get_scary()); } - template + template , int> = 0> _NODISCARD iterator lower_bound(const _Other& _Keyval) { return iterator(_Find_lower_bound(_Keyval)._Bound, _Get_scary()); } - template + template , int> = 0> _NODISCARD const_iterator lower_bound(const _Other& _Keyval) const { return const_iterator(_Find_lower_bound(_Keyval)._Bound, _Get_scary()); } @@ -1446,12 +1448,12 @@ public: return const_iterator(_Find_upper_bound(_Keyval)._Bound, _Get_scary()); } - template + template , int> = 0> _NODISCARD iterator upper_bound(const _Other& _Keyval) { return iterator(_Find_upper_bound(_Keyval)._Bound, _Get_scary()); } - template + template , int> = 0> _NODISCARD const_iterator upper_bound(const _Other& _Keyval) const { return const_iterator(_Find_upper_bound(_Keyval)._Bound, _Get_scary()); } @@ -1468,14 +1470,14 @@ public: return {const_iterator(_Result.first, _Scary), const_iterator(_Result.second, _Scary)}; } - template + template , int> = 0> _NODISCARD pair equal_range(const _Other& _Keyval) { const auto _Result = _Eqrange(_Keyval); const auto _Scary = _Get_scary(); return {iterator(_Result.first, _Scary), iterator(_Result.second, _Scary)}; } - template + template , int> = 0> _NODISCARD pair equal_range(const _Other& _Keyval) const { const auto _Result = _Eqrange(_Keyval); const auto _Scary = _Get_scary(); @@ -1750,8 +1752,10 @@ public: } #if _HAS_CXX23 - template , is_convertible<_Kx, iterator>>, int> = 0> + template , + negation, is_convertible<_Kx, iterator>>>>, + int> = 0> node_type extract(_Kx&& _Keyval) { const const_iterator _Where = find(_Keyval); if (_Where == end()) { diff --git a/stl/inc/xutility b/stl/inc/xutility index 82888aab50..d5ed5a226b 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -537,6 +537,20 @@ struct less_equal { using is_transparent = int; }; +template +_INLINE_VAR constexpr bool _Is_transparent_v = false; + +template +_INLINE_VAR constexpr bool _Is_transparent_v<_Ty, void_t> = true; + +template +struct _Is_transparent : bool_constant<_Is_transparent_v<_Ty>> {}; + +#ifdef __cpp_lib_concepts // TRANSITION, GH-395 +template +concept _Transparent = _Is_transparent_v<_Ty>; +#endif // __cpp_lib_concepts + template struct _Ref_fn { // pass function object by value as a reference template From 42a7d3500ce3514bac60943e137315412e9de260 Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Sat, 27 May 2023 17:41:07 +0200 Subject: [PATCH 2/3] Make `_Supports_transparency` a `constexpr bool` and utilize `enable_if_t` where it is used --- stl/inc/xhash | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stl/inc/xhash b/stl/inc/xhash index 836ed52e21..358f5ac450 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -113,11 +113,10 @@ struct _Uhash_choose_transparency<_Kty, _Hasher, _Keyeq, template using _Deduce_key = const _Keyty&; - template , - is_convertible<_Kx, typename _Container::iterator>>, - int> = 0> - using _Supports_transparency = void; + template + static constexpr bool _Supports_transparency = + !disjunction_v, + is_convertible<_Kx, typename _Container::iterator>>; }; #endif // _HAS_CXX20 @@ -1144,7 +1143,8 @@ public: } #if _HAS_CXX23 - template > + template , int> = 0> size_type erase(_Kx&& _Keyval) noexcept(noexcept(_Erase(_Keyval))) /* strengthened */ { return _Erase(_Keyval); } @@ -1383,7 +1383,8 @@ public: } #if _HAS_CXX23 - template > + template , int> = 0> node_type extract(_Kx&& _Keyval) { const auto _Ptr = _Extract(_Keyval); if (!_Ptr) { From 346896b26113dbe6c7b76aa5ada147d42180f62f Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 30 May 2023 11:16:11 -0700 Subject: [PATCH 3/3] Move new code from `` to ``. --- stl/inc/xmemory | 14 ++++++++++++++ stl/inc/xutility | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/stl/inc/xmemory b/stl/inc/xmemory index e569a652bb..1747cc0a70 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -2567,6 +2567,20 @@ _EXPORT_STD inline void* align(size_t _Bound, size_t _Size, void*& _Ptr, size_t& _Space -= _Off; return _Ptr; } + +template +_INLINE_VAR constexpr bool _Is_transparent_v = false; + +template +_INLINE_VAR constexpr bool _Is_transparent_v<_Ty, void_t> = true; + +template +struct _Is_transparent : bool_constant<_Is_transparent_v<_Ty>> {}; + +#ifdef __cpp_lib_concepts // TRANSITION, GH-395 +template +concept _Transparent = _Is_transparent_v<_Ty>; +#endif // __cpp_lib_concepts _STD_END #pragma pop_macro("new") diff --git a/stl/inc/xutility b/stl/inc/xutility index d5ed5a226b..82888aab50 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -537,20 +537,6 @@ struct less_equal { using is_transparent = int; }; -template -_INLINE_VAR constexpr bool _Is_transparent_v = false; - -template -_INLINE_VAR constexpr bool _Is_transparent_v<_Ty, void_t> = true; - -template -struct _Is_transparent : bool_constant<_Is_transparent_v<_Ty>> {}; - -#ifdef __cpp_lib_concepts // TRANSITION, GH-395 -template -concept _Transparent = _Is_transparent_v<_Ty>; -#endif // __cpp_lib_concepts - template struct _Ref_fn { // pass function object by value as a reference template