forked from OSchip/llvm-project
[libc++] Move __libcpp_erase_if_container into <iterator>, and ADL-proof it.
The container headers don't need to include <functional> for any other reason (or at least, they wouldn't if we moved `less` and `equal_to` out of <functional>), so let's put `__libcpp_erase_if_container` somewhere that's common to the containers but outside of <functional>. Also, calling `std::erase_if(c, pred)` should not trigger ADL. Differential Revision: https://reviews.llvm.org/D99043
This commit is contained in:
parent
772851ca4e
commit
2ac6babcc0
|
@ -3215,22 +3215,6 @@ template <class _Tp>
|
|||
using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
|
||||
#endif // > C++17
|
||||
|
||||
template <class _Container, class _Predicate>
|
||||
inline typename _Container::size_type
|
||||
__libcpp_erase_if_container(_Container& __c, _Predicate __pred) {
|
||||
typename _Container::size_type __old_size = __c.size();
|
||||
|
||||
const typename _Container::iterator __last = __c.end();
|
||||
for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
|
||||
if (__pred(*__iter))
|
||||
__iter = __c.erase(__iter);
|
||||
else
|
||||
++__iter;
|
||||
}
|
||||
|
||||
return __old_size - __c.size();
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_FUNCTIONAL
|
||||
|
|
|
@ -2033,6 +2033,21 @@ _LIBCPP_INLINE_VISIBILITY
|
|||
constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
|
||||
#endif
|
||||
|
||||
template <class _Container, class _Predicate>
|
||||
typename _Container::size_type
|
||||
__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
|
||||
typename _Container::size_type __old_size = __c.size();
|
||||
|
||||
const typename _Container::iterator __last = __c.end();
|
||||
for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
|
||||
if (__pred(*__iter))
|
||||
__iter = __c.erase(__iter);
|
||||
else
|
||||
++__iter;
|
||||
}
|
||||
|
||||
return __old_size - __c.size();
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
|
|
|
@ -480,7 +480,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
|
|||
#include <__config>
|
||||
#include <__tree>
|
||||
#include <__node_handle>
|
||||
#include <iterator>
|
||||
#include <iterator> // __libcpp_erase_if_container
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
@ -1660,7 +1660,7 @@ template <class _Key, class _Tp, class _Compare, class _Allocator,
|
|||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename map<_Key, _Tp, _Compare, _Allocator>::size_type
|
||||
erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2246,7 +2246,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
|
||||
erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
|
||||
_Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -429,6 +429,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
|
|||
#include <__tree>
|
||||
#include <__node_handle>
|
||||
#include <functional>
|
||||
#include <iterator> // __libcpp_erase_if_container
|
||||
#include <version>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
|
@ -964,7 +965,7 @@ template <class _Key, class _Compare, class _Allocator, class _Predicate>
|
|||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename set<_Key, _Compare, _Allocator>::size_type
|
||||
erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1490,7 +1491,7 @@ template <class _Key, class _Compare, class _Allocator, class _Predicate>
|
|||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename multiset<_Key, _Compare, _Allocator>::size_type
|
||||
erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -435,6 +435,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
|
|||
#include <__hash_table>
|
||||
#include <__node_handle>
|
||||
#include <functional>
|
||||
#include <iterator> // __libcpp_erase_if_container
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <version>
|
||||
|
@ -1817,7 +1818,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
|
||||
erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
|
||||
_Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2550,7 +2551,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
|
||||
erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
|
||||
_Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -390,6 +390,7 @@ template <class Value, class Hash, class Pred, class Alloc>
|
|||
#include <__hash_table>
|
||||
#include <__node_handle>
|
||||
#include <functional>
|
||||
#include <iterator> // __libcpp_erase_if_container
|
||||
#include <version>
|
||||
|
||||
#include <__debug>
|
||||
|
@ -1069,7 +1070,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
|
||||
erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
|
||||
_Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1735,7 +1736,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
|
||||
erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
|
||||
_Predicate __pred) {
|
||||
return __libcpp_erase_if_container(__c, __pred);
|
||||
return _VSTD::__libcpp_erase_if_container(__c, __pred);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue