From cc42b902d7b2502ba9b5bb29e9bf44a9c6b1722a Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Wed, 30 Oct 2019 11:24:30 +0000 Subject: [PATCH 1/7] Deprecate experimental::erase --- stl/inc/experimental/deque | 4 ++-- stl/inc/experimental/forward_list | 4 ++-- stl/inc/experimental/list | 4 ++-- stl/inc/experimental/map | 4 ++-- stl/inc/experimental/set | 4 ++-- stl/inc/experimental/string | 4 ++-- stl/inc/experimental/unordered_map | 4 ++-- stl/inc/experimental/unordered_set | 4 ++-- stl/inc/experimental/vector | 4 ++-- stl/inc/yvals_core.h | 13 ++++++++++++- 10 files changed, 30 insertions(+), 19 deletions(-) diff --git a/stl/inc/experimental/deque b/stl/inc/experimental/deque index cf11ee76774..5edf2b50623 100644 --- a/stl/inc/experimental/deque +++ b/stl/inc/experimental/deque @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/experimental/forward_list b/stl/inc/experimental/forward_list index acdede41789..0f35c25a81a 100644 --- a/stl/inc/experimental/forward_list +++ b/stl/inc/experimental/forward_list @@ -24,13 +24,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Cont.remove_if(_Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); } diff --git a/stl/inc/experimental/list b/stl/inc/experimental/list index fa37101cf8e..3441990f893 100644 --- a/stl/inc/experimental/list +++ b/stl/inc/experimental/list @@ -24,13 +24,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Cont.remove_if(_Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); } diff --git a/stl/inc/experimental/map b/stl/inc/experimental/map index 9a3f395b1f5..73172b5c5b1 100644 --- a/stl/inc/experimental/map +++ b/stl/inc/experimental/map @@ -25,12 +25,12 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/set b/stl/inc/experimental/set index 7f22f95f635..6b1216ae893 100644 --- a/stl/inc/experimental/set +++ b/stl/inc/experimental/set @@ -25,12 +25,12 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/string b/stl/inc/experimental/string index 05ae08bbd44..b9d177673e6 100644 --- a/stl/inc/experimental/string +++ b/stl/inc/experimental/string @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/experimental/unordered_map b/stl/inc/experimental/unordered_map index 2fe046632f9..439340274f7 100644 --- a/stl/inc/experimental/unordered_map +++ b/stl/inc/experimental/unordered_map @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/unordered_set b/stl/inc/experimental/unordered_set index d6f85d28880..e743073b529 100644 --- a/stl/inc/experimental/unordered_set +++ b/stl/inc/experimental/unordered_set @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/vector b/stl/inc/experimental/vector index 77dd04cab70..7cfd7dca3e9 100644 --- a/stl/inc/experimental/vector +++ b/stl/inc/experimental/vector @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index f0f7c619058..e4559da28d9 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -835,7 +835,18 @@ #define _CXX20_DEPRECATE_IS_POD #endif // ^^^ warning disabled ^^^ -// next warning number: STL4026 +#if _HAS_CXX20 && !defined(_SILENCE_STD_EXPERIMENTAL_ERASE_DEPRECATION_WARNING) +#define _DEPRECATE_STD_EXPERIMENTAL_ERASE \ + [[deprecated( \ + "warning STL4026: " \ + "std::experimental::erase and std::experimental::erase_if are deprecated. " \ + "Please update to std::erase or std::erase_if. " \ + "You can define _SILENCE_STD_EXPERIMENTAL_ERASE_DEPRECATION_WARNING to suppress this deprecation.")]] +#else // ^^^ warning enabled / warning disabled vvv +#define _DEPRECATE_STD_EXPERIMENTAL_ERASE +#endif // ^^^ warning disabled ^^^ + +// next warning number: STL4027 // LIBRARY FEATURE-TEST MACROS From 60237886d5b0d2f8bd1980f4bab6b28bf2303cfb Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Wed, 30 Oct 2019 14:11:00 +0000 Subject: [PATCH 2/7] Implement P1209R0 --- stl/inc/algorithm | 33 ++++++++++++++++++++++++++++++ stl/inc/deque | 16 +++++++++++++++ stl/inc/experimental/deque | 2 +- stl/inc/experimental/forward_list | 1 + stl/inc/experimental/list | 1 + stl/inc/experimental/map | 2 +- stl/inc/experimental/set | 2 +- stl/inc/experimental/string | 2 +- stl/inc/experimental/unordered_map | 2 +- stl/inc/experimental/unordered_set | 2 +- stl/inc/experimental/vector | 2 +- stl/inc/forward_list | 16 +++++++++++++++ stl/inc/list | 16 +++++++++++++++ stl/inc/map | 18 ++++++++++++++++ stl/inc/set | 18 ++++++++++++++++ stl/inc/unordered_map | 18 ++++++++++++++++ stl/inc/unordered_set | 18 ++++++++++++++++ stl/inc/vector | 16 +++++++++++++++ stl/inc/xstring | 16 +++++++++++++++ stl/inc/yvals_core.h | 1 + 20 files changed, 195 insertions(+), 7 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index ad55394139c..7cf1ac1bb38 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1786,6 +1786,39 @@ template +void _Erase_nodes_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + while (_First != _Last) { + if (_Pred(*_First)) { + _First = _Cont.erase(_First); + } else { + ++_First; + } + } +} + + +// FUNCTION TEMPLATE _Erase_remove_if +template +void _Erase_remove_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + _Seek_wrapped(_First, _STD remove_if(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Pred)); + _Cont.erase(_First, _Last); +} + +// FUNCTION TEMPLATE _Erase_remove +template +void _Erase_remove(_Container& _Cont, const _Uty& _Val) { // erase each element matching _Val + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + _Seek_wrapped(_First, _STD remove(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Val)); + _Cont.erase(_First, _Last); +} + // FUNCTION TEMPLATE unique template _NODISCARD _FwdIt unique(_FwdIt _First, _FwdIt _Last, _Pr _Pred) { // remove each satisfying _Pred with previous diff --git a/stl/inc/deque b/stl/inc/deque index e3729e32e25..553916f780b 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1571,6 +1575,18 @@ template >, deque(_Iter, _Iter, _Alloc = _Alloc())->deque<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} +#endif + template void swap(deque<_Ty, _Alloc>& _Left, deque<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/experimental/deque b/stl/inc/experimental/deque index 5edf2b50623..07015d4fbb4 100644 --- a/stl/inc/experimental/deque +++ b/stl/inc/experimental/deque @@ -9,8 +9,8 @@ #include #if _STL_COMPILER_PREPROCESSOR +#include #include -#include #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) diff --git a/stl/inc/experimental/forward_list b/stl/inc/experimental/forward_list index 0f35c25a81a..17346d93427 100644 --- a/stl/inc/experimental/forward_list +++ b/stl/inc/experimental/forward_list @@ -9,6 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/list b/stl/inc/experimental/list index 3441990f893..113c52e3937 100644 --- a/stl/inc/experimental/list +++ b/stl/inc/experimental/list @@ -9,6 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/map b/stl/inc/experimental/map index 73172b5c5b1..f3dbc229f5c 100644 --- a/stl/inc/experimental/map +++ b/stl/inc/experimental/map @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/set b/stl/inc/experimental/set index 6b1216ae893..dec02abbb1c 100644 --- a/stl/inc/experimental/set +++ b/stl/inc/experimental/set @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/string b/stl/inc/experimental/string index b9d177673e6..63e6b0d25da 100644 --- a/stl/inc/experimental/string +++ b/stl/inc/experimental/string @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/unordered_map b/stl/inc/experimental/unordered_map index 439340274f7..4960752163d 100644 --- a/stl/inc/experimental/unordered_map +++ b/stl/inc/experimental/unordered_map @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/unordered_set b/stl/inc/experimental/unordered_set index e743073b529..2b885bab77f 100644 --- a/stl/inc/experimental/unordered_set +++ b/stl/inc/experimental/unordered_set @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/vector b/stl/inc/experimental/vector index 7cfd7dca3e9..b0ac8f01a06 100644 --- a/stl/inc/experimental/vector +++ b/stl/inc/experimental/vector @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include +#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/forward_list b/stl/inc/forward_list index 34944e4ca0d..6d087e4db48 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1491,6 +1495,18 @@ template >, forward_list(_Iter, _Iter, _Alloc = _Alloc())->forward_list<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Cont.remove_if(_Pass_fn(_Pred)); +} + +template +void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); +} +#endif + template void swap(forward_list<_Ty, _Alloc>& _Left, forward_list<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/list b/stl/inc/list index 208c0ea7a8f..1aa64dc05a2 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1781,6 +1785,18 @@ template >, list(_Iter, _Iter, _Alloc = _Alloc())->list<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Cont.remove_if(_Pass_fn(_Pred)); +} + +template +void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); +} +#endif // _HAS_CXX20 + template void swap(list<_Ty, _Alloc>& _Left, list<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/map b/stl/inc/map index 477df64c8d1..6072074cd12 100644 --- a/stl/inc/map +++ b/stl/inc/map @@ -16,6 +16,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -363,6 +367,13 @@ template map(initializer_list>, _Alloc)->map<_Kty, _Ty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(map<_Kty, _Ty, _Pr, _Alloc>& _Left, map<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept( noexcept(_Left.swap(_Right))) { @@ -510,6 +521,13 @@ template multimap(initializer_list>, _Alloc)->multimap<_Kty, _Ty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept( noexcept(_Left.swap(_Right))) { diff --git a/stl/inc/set b/stl/inc/set index 9031bb02c85..f932e44da56 100644 --- a/stl/inc/set +++ b/stl/inc/set @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -174,6 +178,13 @@ template ::value, in set(initializer_list<_Kty>, _Alloc)->set<_Kty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(set<_Kty, _Pr, _Alloc>& _Left, set<_Kty, _Pr, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { _Left.swap(_Right); @@ -307,6 +318,13 @@ template ::value, in multiset(initializer_list<_Kty>, _Alloc)->multiset<_Kty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(multiset<_Kty, _Pr, _Alloc>& _Left, multiset<_Kty, _Pr, _Alloc>& _Right) noexcept( noexcept(_Left.swap(_Right))) { diff --git a/stl/inc/unordered_map b/stl/inc/unordered_map index 605433b4299..fe3971ea88f 100644 --- a/stl/inc/unordered_map +++ b/stl/inc/unordered_map @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -467,6 +471,13 @@ unordered_map(initializer_list>, _Guide_size_type_t<_Alloc>, _Ha ->unordered_map<_Kty, _Ty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -755,6 +766,13 @@ unordered_multimap(initializer_list>, _Guide_size_type_t<_Alloc> ->unordered_multimap<_Kty, _Ty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { diff --git a/stl/inc/unordered_set b/stl/inc/unordered_set index 27b05834708..e949a31c741 100644 --- a/stl/inc/unordered_set +++ b/stl/inc/unordered_set @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -303,6 +307,13 @@ unordered_set(initializer_list<_Kty>, _Guide_size_type_t<_Alloc>, _Hasher, _Allo ->unordered_set<_Kty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -559,6 +570,13 @@ unordered_multiset(initializer_list<_Kty>, _Guide_size_type_t<_Alloc>, _Hasher, ->unordered_multiset<_Kty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template void swap(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { diff --git a/stl/inc/vector b/stl/inc/vector index cce19334bc7..c8a64d26184 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -14,6 +14,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1755,6 +1759,18 @@ template >, vector(_Iter, _Iter, _Alloc = _Alloc())->vector<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} +#endif // _HAS_CXX20 + template void swap(vector<_Ty, _Alloc>& _Left, vector<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); diff --git a/stl/inc/xstring b/stl/inc/xstring index 82d82d73acf..6c870e00746 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -17,6 +17,10 @@ #include #endif // _HAS_CXX17 +#if _HAS_CXX20 +#include +#endif //_HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -4263,6 +4267,18 @@ basic_string( ->basic_string<_Elem, _Traits, _Alloc>; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template +void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} +#endif // _HAS_CXX20 + template void swap(basic_string<_Elem, _Traits, _Alloc>& _Left, basic_string<_Elem, _Traits, _Alloc>& _Right) noexcept /* strengthened */ { diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index e4559da28d9..542a6324731 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -964,6 +964,7 @@ #endif // _HAS_STD_BOOLEAN #endif // defined(__cpp_concepts) && __cpp_concepts > 201507L +#define __cpp_lib_erase_if 201811L #define __cpp_lib_generic_unordered_lookup 201811L #define __cpp_lib_list_remove_return_type 201806L #define __cpp_lib_to_array 201907L From 87684a602a91f6380c873ad31ce84718fa3169ef Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Wed, 30 Oct 2019 17:48:44 +0000 Subject: [PATCH 3/7] Update yvals_core.h --- stl/inc/yvals_core.h | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 542a6324731..ff257baf896 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -47,6 +47,7 @@ // P0898R3 Standard Library Concepts // P0919R3 Heterogeneous Lookup For Unordered Containers // P0966R1 string::reserve() Should Not Shrink +// P1209R0 erase_if(), erase() // P1227R2 Signed std::ssize(), Unsigned span::size() // (partially implemented) // P1357R1 is_bounded_array, is_unbounded_array From bd897a9d0868cc27206fb11c0a33a33c8d445ac3 Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Thu, 31 Oct 2019 10:30:52 +0000 Subject: [PATCH 4/7] Update deprecations and remove --- stl/CMakeLists.txt | 1 - stl/inc/experimental/deque | 4 +- stl/inc/experimental/forward_list | 4 +- stl/inc/experimental/list | 4 +- stl/inc/experimental/map | 4 +- stl/inc/experimental/set | 4 +- stl/inc/experimental/string | 4 +- stl/inc/experimental/unordered_map | 8 ++-- stl/inc/experimental/unordered_set | 7 ++- stl/inc/experimental/vector | 4 +- stl/inc/experimental/xutility | 69 ------------------------------ stl/inc/yvals_core.h | 16 +++---- 12 files changed, 29 insertions(+), 100 deletions(-) delete mode 100644 stl/inc/experimental/xutility diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 2a8c5f93678..41e5d8acfdd 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -135,7 +135,6 @@ set(HEADERS ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/unordered_map ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/unordered_set ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/vector - ${CMAKE_CURRENT_LIST_DIR}/inc/experimental/xutility ${CMAKE_CURRENT_LIST_DIR}/inc/filesystem ${CMAKE_CURRENT_LIST_DIR}/inc/forward_list ${CMAKE_CURRENT_LIST_DIR}/inc/fstream diff --git a/stl/inc/experimental/deque b/stl/inc/experimental/deque index 07015d4fbb4..bb56031ad8e 100644 --- a/stl/inc/experimental/deque +++ b/stl/inc/experimental/deque @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_EXPERIMENTAL_ERASE void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/experimental/forward_list b/stl/inc/experimental/forward_list index 17346d93427..74e86500638 100644 --- a/stl/inc/experimental/forward_list +++ b/stl/inc/experimental/forward_list @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { _Cont.remove_if(_Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_EXPERIMENTAL_ERASE void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); } diff --git a/stl/inc/experimental/list b/stl/inc/experimental/list index 113c52e3937..515e6d4a7c5 100644 --- a/stl/inc/experimental/list +++ b/stl/inc/experimental/list @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { _Cont.remove_if(_Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_EXPERIMENTAL_ERASE void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); } diff --git a/stl/inc/experimental/map b/stl/inc/experimental/map index f3dbc229f5c..693c61280dd 100644 --- a/stl/inc/experimental/map +++ b/stl/inc/experimental/map @@ -25,12 +25,12 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/set b/stl/inc/experimental/set index dec02abbb1c..929f6d91d7a 100644 --- a/stl/inc/experimental/set +++ b/stl/inc/experimental/set @@ -25,12 +25,12 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/string b/stl/inc/experimental/string index 63e6b0d25da..f8f391e02be 100644 --- a/stl/inc/experimental/string +++ b/stl/inc/experimental/string @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_EXPERIMENTAL_ERASE void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/experimental/unordered_map b/stl/inc/experimental/unordered_map index 4960752163d..31dbe18baef 100644 --- a/stl/inc/experimental/unordered_map +++ b/stl/inc/experimental/unordered_map @@ -25,14 +25,14 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, - _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if( + unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, - _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if( + unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/unordered_set b/stl/inc/experimental/unordered_set index 2b885bab77f..eaa3b07771c 100644 --- a/stl/inc/experimental/unordered_set +++ b/stl/inc/experimental/unordered_set @@ -25,14 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, - _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, - _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if( + unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } diff --git a/stl/inc/experimental/vector b/stl/inc/experimental/vector index b0ac8f01a06..4e1ee236d93 100644 --- a/stl/inc/experimental/vector +++ b/stl/inc/experimental/vector @@ -25,13 +25,13 @@ namespace experimental { // FUNCTION TEMPLATE erase_if template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + _DEPRECATE_EXPERIMENTAL_ERASE void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { _Erase_remove_if(_Cont, _Pass_fn(_Pred)); } // FUNCTION TEMPLATE erase template - _DEPRECATE_STD_EXPERIMENTAL_ERASE void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { // erase each element matching _Val + _DEPRECATE_EXPERIMENTAL_ERASE void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { _Erase_remove(_Cont, _Val); } diff --git a/stl/inc/experimental/xutility b/stl/inc/experimental/xutility deleted file mode 100644 index 83ee7564446..00000000000 --- a/stl/inc/experimental/xutility +++ /dev/null @@ -1,69 +0,0 @@ -// xutility experimental header - -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#pragma once -#ifndef _EXPERIMENTAL_XUTILITY_ -#define _EXPERIMENTAL_XUTILITY_ -#include -#if _STL_COMPILER_PREPROCESSOR - -#include -#include - -#pragma pack(push, _CRT_PACKING) -#pragma warning(push, _STL_WARNING_LEVEL) -#pragma warning(disable : _STL_DISABLED_WARNINGS) -_STL_DISABLE_CLANG_WARNINGS -#pragma push_macro("new") -#undef new - -_STD_BEGIN -namespace experimental { - inline namespace fundamentals_v2 { - - // FUNCTION TEMPLATE _Erase_nodes_if - template - void _Erase_nodes_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - while (_First != _Last) { - if (_Pred(*_First)) { - _First = _Cont.erase(_First); - } else { - ++_First; - } - } - } - - - // FUNCTION TEMPLATE _Erase_remove_if - template - void _Erase_remove_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - _Seek_wrapped(_First, _STD remove_if(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Pred)); - _Cont.erase(_First, _Last); - } - - // FUNCTION TEMPLATE _Erase_remove - template - void _Erase_remove(_Container& _Cont, const _Uty& _Val) { // erase each element matching _Val - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - _Seek_wrapped(_First, _STD remove(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Val)); - _Cont.erase(_First, _Last); - } - - } // namespace fundamentals_v2 -} // namespace experimental -_STD_END - -#pragma pop_macro("new") -_STL_RESTORE_CLANG_WARNINGS -#pragma warning(pop) -#pragma pack(pop) - -#endif // _STL_COMPILER_PREPROCESSOR -#endif // _EXPERIMENTAL_XUTILITY_ diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index ff257baf896..9b84fcc4e1b 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -836,15 +836,15 @@ #define _CXX20_DEPRECATE_IS_POD #endif // ^^^ warning disabled ^^^ -#if _HAS_CXX20 && !defined(_SILENCE_STD_EXPERIMENTAL_ERASE_DEPRECATION_WARNING) -#define _DEPRECATE_STD_EXPERIMENTAL_ERASE \ - [[deprecated( \ - "warning STL4026: " \ - "std::experimental::erase and std::experimental::erase_if are deprecated. " \ - "Please update to std::erase or std::erase_if. " \ - "You can define _SILENCE_STD_EXPERIMENTAL_ERASE_DEPRECATION_WARNING to suppress this deprecation.")]] +#if _HAS_CXX20 && !defined(_SILENCE_EXPERIMENTAL_ERASE_DEPRECATION_WARNING) +#define _DEPRECATE_EXPERIMENTAL_ERASE \ + [[deprecated("warning STL4026: " \ + "std::experimental::erase() and std::experimental::erase_if() are deprecated by Microsoft and will " \ + "be REMOVED. They are superseded by std::erase() and std::erase_if(). " \ + "You can define _SILENCE_EXPERIMENTAL_ERASE_DEPRECATION_WARNING to acknowledge that you have " \ + "received this warning.")]] #else // ^^^ warning enabled / warning disabled vvv -#define _DEPRECATE_STD_EXPERIMENTAL_ERASE +#define _DEPRECATE_EXPERIMENTAL_ERASE #endif // ^^^ warning disabled ^^^ // next warning number: STL4027 From 9ee3c6885dfc136b9c0273742b21113511236643 Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Thu, 31 Oct 2019 11:04:22 +0000 Subject: [PATCH 5/7] move and reorder erase/erase_if --- stl/inc/deque | 24 ++++++++++++------------ stl/inc/forward_list | 24 ++++++++++++------------ stl/inc/list | 24 ++++++++++++------------ stl/inc/map | 24 +++++++++++------------- stl/inc/set | 26 ++++++++++++-------------- stl/inc/unordered_map | 26 ++++++++++++-------------- stl/inc/unordered_set | 26 ++++++++++++-------------- stl/inc/vector | 24 ++++++++++++------------ stl/inc/xstring | 24 ++++++++++++------------ 9 files changed, 107 insertions(+), 115 deletions(-) diff --git a/stl/inc/deque b/stl/inc/deque index 553916f780b..bc6998f6006 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -1575,18 +1575,6 @@ template >, deque(_Iter, _Iter, _Alloc = _Alloc())->deque<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { - _Erase_remove_if(_Cont, _Pass_fn(_Pred)); -} - -template -void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { - _Erase_remove(_Cont, _Val); -} -#endif - template void swap(deque<_Ty, _Alloc>& _Left, deque<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); @@ -1624,6 +1612,18 @@ _NODISCARD bool operator>=(const deque<_Ty, _Alloc>& _Left, const deque<_Ty, _Al return !(_Left < _Right); } +#if _HAS_CXX20 +template +void erase(deque<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} + +template +void erase_if(deque<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template diff --git a/stl/inc/forward_list b/stl/inc/forward_list index 6d087e4db48..f8a0cc68e4a 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -1495,18 +1495,6 @@ template >, forward_list(_Iter, _Iter, _Alloc = _Alloc())->forward_list<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { - _Cont.remove_if(_Pass_fn(_Pred)); -} - -template -void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { - _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); -} -#endif - template void swap(forward_list<_Ty, _Alloc>& _Left, forward_list<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); @@ -1542,6 +1530,18 @@ _NODISCARD bool operator>=(const forward_list<_Ty, _Alloc>& _Left, const forward return !(_Left < _Right); } +#if _HAS_CXX20 +template +void erase(forward_list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); +} + +template +void erase_if(forward_list<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Cont.remove_if(_Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template diff --git a/stl/inc/list b/stl/inc/list index 1aa64dc05a2..8bb00a22b99 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -1785,18 +1785,6 @@ template >, list(_Iter, _Iter, _Alloc = _Alloc())->list<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { - _Cont.remove_if(_Pass_fn(_Pred)); -} - -template -void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { - _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); -} -#endif // _HAS_CXX20 - template void swap(list<_Ty, _Alloc>& _Left, list<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); @@ -1832,6 +1820,18 @@ _NODISCARD bool operator>=(const list<_Ty, _Alloc>& _Left, const list<_Ty, _Allo return !(_Left < _Right); } +#if _HAS_CXX20 +template +void erase(list<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Cont.remove_if([&](_Ty& _Elem) { return _Elem == _Val; }); +} + +template +void erase_if(list<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Cont.remove_if(_Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template diff --git a/stl/inc/map b/stl/inc/map index 6072074cd12..aa7b5fce94f 100644 --- a/stl/inc/map +++ b/stl/inc/map @@ -367,13 +367,6 @@ template map(initializer_list>, _Alloc)->map<_Kty, _Ty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(map<_Kty, _Ty, _Pr, _Alloc>& _Left, map<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept( noexcept(_Left.swap(_Right))) { @@ -521,18 +514,23 @@ template multimap(initializer_list>, _Alloc)->multimap<_Kty, _Ty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 +template +void swap(multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept( + noexcept(_Left.swap(_Right))) { + _Left.swap(_Right); +} + #if _HAS_CXX20 template -void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { +void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } -#endif // _HAS_CXX20 -template -void swap(multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, multimap<_Kty, _Ty, _Pr, _Alloc>& _Right) noexcept( - noexcept(_Left.swap(_Right))) { - _Left.swap(_Right); +template +void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); } +#endif // _HAS_CXX20 #if _HAS_CXX17 namespace pmr { diff --git a/stl/inc/set b/stl/inc/set index f932e44da56..ed44e2b3a1a 100644 --- a/stl/inc/set +++ b/stl/inc/set @@ -178,13 +178,6 @@ template ::value, in set(initializer_list<_Kty>, _Alloc)->set<_Kty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(set<_Kty, _Pr, _Alloc>& _Left, set<_Kty, _Pr, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { _Left.swap(_Right); @@ -318,19 +311,24 @@ template ::value, in multiset(initializer_list<_Kty>, _Alloc)->multiset<_Kty, less<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(multiset<_Kty, _Pr, _Alloc>& _Left, multiset<_Kty, _Pr, _Alloc>& _Right) noexcept( noexcept(_Left.swap(_Right))) { _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template > diff --git a/stl/inc/unordered_map b/stl/inc/unordered_map index fe3971ea88f..dd70170dfb6 100644 --- a/stl/inc/unordered_map +++ b/stl/inc/unordered_map @@ -471,13 +471,6 @@ unordered_map(initializer_list>, _Guide_size_type_t<_Alloc>, _Ha ->unordered_map<_Kty, _Ty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -766,13 +759,6 @@ unordered_multimap(initializer_list>, _Guide_size_type_t<_Alloc> ->unordered_multimap<_Kty, _Ty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -798,6 +784,18 @@ namespace _DEPRECATE_TR1_NAMESPACE tr1 { } // namespace tr1 #endif // _HAS_TR1_NAMESPACE +#if _HAS_CXX20 +template +void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template , class _Keyeq = equal_to<_Kty>> diff --git a/stl/inc/unordered_set b/stl/inc/unordered_set index e949a31c741..fba1eb598a2 100644 --- a/stl/inc/unordered_set +++ b/stl/inc/unordered_set @@ -307,13 +307,6 @@ unordered_set(initializer_list<_Kty>, _Guide_size_type_t<_Alloc>, _Hasher, _Allo ->unordered_set<_Kty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -570,13 +563,6 @@ unordered_multiset(initializer_list<_Kty>, _Guide_size_type_t<_Alloc>, _Hasher, ->unordered_multiset<_Kty, _Hasher, equal_to<_Kty>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - template void swap(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) noexcept(noexcept(_Left.swap(_Right))) { @@ -602,6 +588,18 @@ namespace _DEPRECATE_TR1_NAMESPACE tr1 { } // namespace tr1 #endif // _HAS_TR1_NAMESPACE +#if _HAS_CXX20 +template +void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} + +template +void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template , class _Keyeq = equal_to<_Kty>> diff --git a/stl/inc/vector b/stl/inc/vector index c8a64d26184..b9d72c80a2b 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -1759,18 +1759,6 @@ template >, vector(_Iter, _Iter, _Alloc = _Alloc())->vector<_Iter_value_t<_Iter>, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { - _Erase_remove_if(_Cont, _Pass_fn(_Pred)); -} - -template -void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { - _Erase_remove(_Cont, _Val); -} -#endif // _HAS_CXX20 - template void swap(vector<_Ty, _Alloc>& _Left, vector<_Ty, _Alloc>& _Right) noexcept /* strengthened */ { _Left.swap(_Right); @@ -2879,6 +2867,18 @@ struct hash> { } }; +#if _HAS_CXX20 +template +void erase(vector<_Ty, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} + +template +void erase_if(vector<_Ty, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template diff --git a/stl/inc/xstring b/stl/inc/xstring index 6c870e00746..c8303e00034 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -4267,18 +4267,6 @@ basic_string( ->basic_string<_Elem, _Traits, _Alloc>; #endif // _HAS_CXX17 -#if _HAS_CXX20 -template -void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { - _Erase_remove_if(_Cont, _Pass_fn(_Pred)); -} - -template -void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { - _Erase_remove(_Cont, _Val); -} -#endif // _HAS_CXX20 - template void swap(basic_string<_Elem, _Traits, _Alloc>& _Left, basic_string<_Elem, _Traits, _Alloc>& _Right) noexcept /* strengthened */ { @@ -4591,6 +4579,18 @@ inline namespace literals { } // namespace string_literals } // namespace literals +#if _HAS_CXX20 +template +void erase(basic_string<_Elem, _Traits, _Alloc>& _Cont, const _Uty& _Val) { + _Erase_remove(_Cont, _Val); +} + +template +void erase_if(basic_string<_Elem, _Traits, _Alloc>& _Cont, _Pr _Pred) { + _Erase_remove_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + #if _HAS_CXX17 namespace pmr { template > From 41d5b02dc1c0e3b4b7c5ce01e45499917bea7493 Mon Sep 17 00:00:00 2001 From: Daniel Marshall Date: Thu, 31 Oct 2019 19:10:58 +0000 Subject: [PATCH 6/7] moved _Erase and remove and friends to --- stl/inc/algorithm | 75 ------------------------------ stl/inc/deque | 4 -- stl/inc/experimental/deque | 1 - stl/inc/experimental/forward_list | 1 - stl/inc/experimental/list | 1 - stl/inc/experimental/map | 1 - stl/inc/experimental/set | 1 - stl/inc/experimental/string | 1 - stl/inc/experimental/unordered_map | 1 - stl/inc/experimental/unordered_set | 1 - stl/inc/experimental/vector | 1 - stl/inc/forward_list | 4 -- stl/inc/list | 4 -- stl/inc/map | 4 -- stl/inc/set | 4 -- stl/inc/unordered_map | 4 -- stl/inc/unordered_set | 4 -- stl/inc/vector | 4 -- stl/inc/xmemory | 74 +++++++++++++++++++++++++++++ stl/inc/xstring | 4 -- 20 files changed, 74 insertions(+), 120 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 7cf1ac1bb38..716eca572be 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1733,92 +1733,17 @@ _DestTy* remove_copy_if( #endif // _ITERATOR_DEBUG_ARRAY_OVERLOADS #endif // _HAS_CXX17 -// FUNCTION TEMPLATE remove -template -_NODISCARD _FwdIt remove(_FwdIt _First, const _FwdIt _Last, const _Ty& _Val) { // remove each matching _Val - _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_First); - const auto _ULast = _Get_unwrapped(_Last); - _UFirst = _Find_unchecked(_UFirst, _ULast, _Val); - auto _UNext = _UFirst; - if (_UFirst != _ULast) { - while (++_UFirst != _ULast) { - if (!(*_UFirst == _Val)) { - *_UNext = _STD move(*_UFirst); - ++_UNext; - } - } - } - - _Seek_wrapped(_First, _UNext); - return _First; -} - #if _HAS_CXX17 template = 0> _NODISCARD _FwdIt remove( _ExPo&& _Exec, const _FwdIt _First, const _FwdIt _Last, const _Ty& _Val) noexcept; // terminates #endif // _HAS_CXX17 -// FUNCTION TEMPLATE remove_if -template -_NODISCARD _FwdIt remove_if(_FwdIt _First, const _FwdIt _Last, _Pr _Pred) { // remove each satisfying _Pred - _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_First); - const auto _ULast = _Get_unwrapped(_Last); - _UFirst = _STD find_if(_UFirst, _ULast, _Pass_fn(_Pred)); - auto _UNext = _UFirst; - if (_UFirst != _ULast) { - while (++_UFirst != _ULast) { - if (!_Pred(*_UFirst)) { - *_UNext = _STD move(*_UFirst); - ++_UNext; - } - } - } - - _Seek_wrapped(_First, _UNext); - return _First; -} - #if _HAS_CXX17 template = 0> _NODISCARD _FwdIt remove_if(_ExPo&& _Exec, _FwdIt _First, const _FwdIt _Last, _Pr _Pred) noexcept; // terminates #endif // _HAS_CXX17 -// FUNCTION TEMPLATE _Erase_nodes_if -template -void _Erase_nodes_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - while (_First != _Last) { - if (_Pred(*_First)) { - _First = _Cont.erase(_First); - } else { - ++_First; - } - } -} - - -// FUNCTION TEMPLATE _Erase_remove_if -template -void _Erase_remove_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - _Seek_wrapped(_First, _STD remove_if(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Pred)); - _Cont.erase(_First, _Last); -} - -// FUNCTION TEMPLATE _Erase_remove -template -void _Erase_remove(_Container& _Cont, const _Uty& _Val) { // erase each element matching _Val - auto _First = _Cont.begin(); - const auto _Last = _Cont.end(); - _Seek_wrapped(_First, _STD remove(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Val)); - _Cont.erase(_First, _Last); -} - // FUNCTION TEMPLATE unique template _NODISCARD _FwdIt unique(_FwdIt _First, _FwdIt _Last, _Pr _Pred) { // remove each satisfying _Pred with previous diff --git a/stl/inc/deque b/stl/inc/deque index bc6998f6006..2d5a6b949bf 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/experimental/deque b/stl/inc/experimental/deque index bb56031ad8e..3b0bf2eb361 100644 --- a/stl/inc/experimental/deque +++ b/stl/inc/experimental/deque @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/forward_list b/stl/inc/experimental/forward_list index 74e86500638..ec2323808a8 100644 --- a/stl/inc/experimental/forward_list +++ b/stl/inc/experimental/forward_list @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/list b/stl/inc/experimental/list index 515e6d4a7c5..d4d1314bcf8 100644 --- a/stl/inc/experimental/list +++ b/stl/inc/experimental/list @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/map b/stl/inc/experimental/map index 693c61280dd..3c5bab0cd3c 100644 --- a/stl/inc/experimental/map +++ b/stl/inc/experimental/map @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/set b/stl/inc/experimental/set index 929f6d91d7a..9fc738f5d49 100644 --- a/stl/inc/experimental/set +++ b/stl/inc/experimental/set @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/string b/stl/inc/experimental/string index f8f391e02be..a6bc3945435 100644 --- a/stl/inc/experimental/string +++ b/stl/inc/experimental/string @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/unordered_map b/stl/inc/experimental/unordered_map index 31dbe18baef..106746b0e57 100644 --- a/stl/inc/experimental/unordered_map +++ b/stl/inc/experimental/unordered_map @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/unordered_set b/stl/inc/experimental/unordered_set index eaa3b07771c..44f4e6c4db5 100644 --- a/stl/inc/experimental/unordered_set +++ b/stl/inc/experimental/unordered_set @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/experimental/vector b/stl/inc/experimental/vector index 4e1ee236d93..e4422ebabd2 100644 --- a/stl/inc/experimental/vector +++ b/stl/inc/experimental/vector @@ -9,7 +9,6 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include #include #pragma pack(push, _CRT_PACKING) diff --git a/stl/inc/forward_list b/stl/inc/forward_list index f8a0cc68e4a..b1a6497e2b1 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/list b/stl/inc/list index 8bb00a22b99..b49799830d8 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/map b/stl/inc/map index aa7b5fce94f..7a89712b8a2 100644 --- a/stl/inc/map +++ b/stl/inc/map @@ -16,10 +16,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/set b/stl/inc/set index ed44e2b3a1a..1f1e4eaaf42 100644 --- a/stl/inc/set +++ b/stl/inc/set @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/unordered_map b/stl/inc/unordered_map index dd70170dfb6..b555bb0b028 100644 --- a/stl/inc/unordered_map +++ b/stl/inc/unordered_map @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/unordered_set b/stl/inc/unordered_set index fba1eb598a2..0b803ee25d8 100644 --- a/stl/inc/unordered_set +++ b/stl/inc/unordered_set @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/vector b/stl/inc/vector index b9d72c80a2b..15e292759d2 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -14,10 +14,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif // _HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 8705f7da73e..4edf5e33d06 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -1994,6 +1994,80 @@ struct _Alloc_temporary { _Traits::destroy(_Al, _STD addressof(_Storage._Value)); } }; + +// FUNCTION TEMPLATE remove +template +_NODISCARD _FwdIt remove(_FwdIt _First, const _FwdIt _Last, const _Ty& _Val) { // remove each matching _Val + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_First); + const auto _ULast = _Get_unwrapped(_Last); + _UFirst = _Find_unchecked(_UFirst, _ULast, _Val); + auto _UNext = _UFirst; + if (_UFirst != _ULast) { + while (++_UFirst != _ULast) { + if (!(*_UFirst == _Val)) { + *_UNext = _STD move(*_UFirst); + ++_UNext; + } + } + } + + _Seek_wrapped(_First, _UNext); + return _First; +} + +// FUNCTION TEMPLATE remove_if +template +_NODISCARD _FwdIt remove_if(_FwdIt _First, const _FwdIt _Last, _Pr _Pred) { // remove each satisfying _Pred + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_First); + const auto _ULast = _Get_unwrapped(_Last); + _UFirst = _STD find_if(_UFirst, _ULast, _Pass_fn(_Pred)); + auto _UNext = _UFirst; + if (_UFirst != _ULast) { + while (++_UFirst != _ULast) { + if (!_Pred(*_UFirst)) { + *_UNext = _STD move(*_UFirst); + ++_UNext; + } + } + } + + _Seek_wrapped(_First, _UNext); + return _First; +} + +// FUNCTION TEMPLATE _Erase_remove +template +void _Erase_remove(_Container& _Cont, const _Uty& _Val) { // erase each element matching _Val + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + _Seek_wrapped(_First, _STD remove(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Val)); + _Cont.erase(_First, _Last); +} + +// FUNCTION TEMPLATE _Erase_remove_if +template +void _Erase_remove_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + _Seek_wrapped(_First, _STD remove_if(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Pred)); + _Cont.erase(_First, _Last); +} + +// FUNCTION TEMPLATE _Erase_nodes_if +template +void _Erase_nodes_if(_Container& _Cont, _Pr _Pred) { // erase each element satisfying _Pred + auto _First = _Cont.begin(); + const auto _Last = _Cont.end(); + while (_First != _Last) { + if (_Pred(*_First)) { + _First = _Cont.erase(_First); + } else { + ++_First; + } + } +} _STD_END #pragma pop_macro("new") diff --git a/stl/inc/xstring b/stl/inc/xstring index c8303e00034..ef7d278c659 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -17,10 +17,6 @@ #include #endif // _HAS_CXX17 -#if _HAS_CXX20 -#include -#endif //_HAS_CXX20 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) From 4f0c038b49f7e49b49f5c18b9676b86d5a1dff58 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 31 Oct 2019 19:32:56 -0700 Subject: [PATCH 7/7] Consistently place erase_if() definitions. --- stl/inc/map | 12 +++++++----- stl/inc/set | 12 +++++++----- stl/inc/unordered_map | 26 ++++++++++++++------------ stl/inc/unordered_set | 26 ++++++++++++++------------ 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/stl/inc/map b/stl/inc/map index 7a89712b8a2..2d93d3815c4 100644 --- a/stl/inc/map +++ b/stl/inc/map @@ -369,6 +369,13 @@ void swap(map<_Kty, _Ty, _Pr, _Alloc>& _Left, map<_Kty, _Ty, _Pr, _Alloc>& _Righ _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + // CLASS TEMPLATE multimap template , class _Alloc = allocator>> class multimap : public _Tree<_Tmap_traits<_Kty, _Ty, _Pr, _Alloc, true>> { @@ -517,11 +524,6 @@ void swap(multimap<_Kty, _Ty, _Pr, _Alloc>& _Left, multimap<_Kty, _Ty, _Pr, _All } #if _HAS_CXX20 -template -void erase_if(map<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} - template void erase_if(multimap<_Kty, _Ty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); diff --git a/stl/inc/set b/stl/inc/set index 1f1e4eaaf42..47ec4bd0c50 100644 --- a/stl/inc/set +++ b/stl/inc/set @@ -179,6 +179,13 @@ void swap(set<_Kty, _Pr, _Alloc>& _Left, set<_Kty, _Pr, _Alloc>& _Right) noexcep _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + // CLASS TEMPLATE multiset template , class _Alloc = allocator<_Kty>> class multiset : public _Tree<_Tset_traits<_Kty, _Pr, _Alloc, true>> { @@ -314,11 +321,6 @@ void swap(multiset<_Kty, _Pr, _Alloc>& _Left, multiset<_Kty, _Pr, _Alloc>& _Righ } #if _HAS_CXX20 -template -void erase_if(set<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} - template void erase_if(multiset<_Kty, _Keylt, _Alloc>& _Cont, _Pr _Pred) { _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); diff --git a/stl/inc/unordered_map b/stl/inc/unordered_map index b555bb0b028..e8b647aa1aa 100644 --- a/stl/inc/unordered_map +++ b/stl/inc/unordered_map @@ -473,6 +473,13 @@ void swap(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template _NODISCARD bool operator==(const unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, const unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) { @@ -761,6 +768,13 @@ void swap(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template _NODISCARD bool operator==(const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Left, const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Right) { @@ -780,18 +794,6 @@ namespace _DEPRECATE_TR1_NAMESPACE tr1 { } // namespace tr1 #endif // _HAS_TR1_NAMESPACE -#if _HAS_CXX20 -template -void erase_if(unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} - -template -void erase_if(unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - #if _HAS_CXX17 namespace pmr { template , class _Keyeq = equal_to<_Kty>> diff --git a/stl/inc/unordered_set b/stl/inc/unordered_set index 0b803ee25d8..d2bc48453b0 100644 --- a/stl/inc/unordered_set +++ b/stl/inc/unordered_set @@ -309,6 +309,13 @@ void swap(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template _NODISCARD bool operator==(const unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, const unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) { @@ -565,6 +572,13 @@ void swap(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, _Left.swap(_Right); } +#if _HAS_CXX20 +template +void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { + _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); +} +#endif // _HAS_CXX20 + template _NODISCARD bool operator==(const unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, const unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) { @@ -584,18 +598,6 @@ namespace _DEPRECATE_TR1_NAMESPACE tr1 { } // namespace tr1 #endif // _HAS_TR1_NAMESPACE -#if _HAS_CXX20 -template -void erase_if(unordered_set<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} - -template -void erase_if(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Cont, _Pr _Pred) { - _Erase_nodes_if(_Cont, _Pass_fn(_Pred)); -} -#endif // _HAS_CXX20 - #if _HAS_CXX17 namespace pmr { template , class _Keyeq = equal_to<_Kty>>