{ __lhs.swap(__rhs); }
} // namespace __debug
+
+#ifdef __glibcxx_erase_if // C++ >= 20 && HOSTED
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+ template<typename _Tp, typename _Alloc, typename _Predicate>
+ inline typename __debug::deque<_Tp, _Alloc>::size_type
+ erase_if(__debug::deque<_Tp, _Alloc>& __cont, _Predicate __pred)
+ {
+ _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __unsafe_cont = __cont;
+ const auto __osz = __cont.size();
+ const auto __end = __unsafe_cont.end();
+ auto __removed = std::__remove_if(__unsafe_cont.begin(), __end,
+ std::move(__pred));
+ if (__removed != __end)
+ {
+ __cont.erase(__niter_wrap(__cont.begin(), __removed),
+ __cont.end());
+ return __osz - __cont.size();
+ }
+
+ return 0;
+ }
+
+ template<typename _Tp, typename _Alloc, typename _Up = _Tp>
+ inline typename __debug::deque<_Tp, _Alloc>::size_type
+ erase(__debug::deque<_Tp, _Alloc>& __cont, const _Up& __value)
+ { return std::erase_if(__cont, __gnu_cxx::__ops::__equal_to(__value)); }
+_GLIBCXX_END_NAMESPACE_VERSION
+#endif // __cpp_lib_erase_if
} // namespace std
#endif
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _Alloc, typename _Predicate>
- inline typename deque<_Tp, _Alloc>::size_type
- erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred)
+ inline typename _GLIBCXX_STD_C::deque<_Tp, _Alloc>::size_type
+ erase_if(_GLIBCXX_STD_C::deque<_Tp, _Alloc>& __cont, _Predicate __pred)
{
- using namespace __gnu_cxx;
- _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __ucont = __cont;
const auto __osz = __cont.size();
- const auto __end = __ucont.end();
- auto __removed = std::__remove_if(__ucont.begin(), __end,
+ const auto __end = __cont.end();
+ auto __removed = std::__remove_if(__cont.begin(), __end,
std::move(__pred));
if (__removed != __end)
{
- __cont.erase(__niter_wrap(__cont.begin(), __removed),
- __cont.end());
+ __cont.erase(__removed, __end);
return __osz - __cont.size();
}
template<typename _Tp, typename _Alloc,
typename _Up _GLIBCXX26_DEF_VAL_T(_Tp)>
- inline typename deque<_Tp, _Alloc>::size_type
- erase(deque<_Tp, _Alloc>& __cont, const _Up& __value)
+ inline typename _GLIBCXX_STD_C::deque<_Tp, _Alloc>::size_type
+ erase(_GLIBCXX_STD_C::deque<_Tp, _Alloc>& __cont, const _Up& __value)
{ return std::erase_if(__cont, __gnu_cxx::__ops::__equal_to(__value)); }
_GLIBCXX_END_NAMESPACE_VERSION
--- /dev/null
+// { dg-do run { target c++20 } }
+// { dg-require-debug-mode "" }
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ std::deque<int> d;
+
+ for (int i = 0; i != 10; ++i)
+ d.push_back(i);
+
+ auto before = d.begin() + 4;
+ auto last = d.end() - 1;
+
+ VERIFY( std::erase(d, 6) == 1 );
+
+ VERIFY(before._M_dereferenceable());
+ VERIFY(last._M_singular());
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++20 } }
+
+#include <debug/deque>
+#include <testsuite_hooks.h>
+
+using __gnu_debug::deque;
+
+void test01()
+{
+ deque<int> d;
+
+ for (int i = 0; i != 10; ++i)
+ d.push_back(i);
+
+ auto before = d.begin() + 4;
+ auto last = d.end() -1;
+
+ VERIFY( std::erase(d, 6) == 1 );
+
+ VERIFY(before._M_dereferenceable());
+ VERIFY(last._M_singular());
+}
+
+int main()
+{
+ test01();
+ return 0;
+}