} // namespace __detail::__variant
#endif // C++17
+#ifdef __glibcxx_erase_if // C++ >= 20 && HOSTED
+ template<typename _Tp, typename _Alloc, typename _Predicate>
+ constexpr typename __debug::vector<_Tp, _Alloc>::size_type
+ erase_if(__debug::vector<_Tp, _Alloc>& __cont, _Predicate __pred)
+ {
+ _GLIBCXX_STD_C::vector<_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>
+ constexpr typename __debug::vector<_Tp, _Alloc>::size_type
+ erase(__debug::vector<_Tp, _Alloc>& __cont, const _Up& __value)
+ { return std::erase_if(__cont, __gnu_cxx::__ops::__equal_to(__value)); }
+#endif // __glibcxx_erase_if
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _Alloc, typename _Predicate>
- constexpr typename vector<_Tp, _Alloc>::size_type
- erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred)
+ constexpr typename _GLIBCXX_STD_C::vector<_Tp, _Alloc>::size_type
+ erase_if(_GLIBCXX_STD_C::vector<_Tp, _Alloc>& __cont, _Predicate __pred)
{
- using namespace __gnu_cxx;
- _GLIBCXX_STD_C::vector<_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)>
- constexpr typename vector<_Tp, _Alloc>::size_type
- erase(vector<_Tp, _Alloc>& __cont, const _Up& __value)
+ constexpr typename _GLIBCXX_STD_C::vector<_Tp, _Alloc>::size_type
+ erase(_GLIBCXX_STD_C::vector<_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-add-options no_pch }
+// { dg-require-debug-mode "" }
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ std::vector<int> v;
+
+ for (int i = 0; i != 10; ++i)
+ v.push_back(i);
+
+ auto before = v.begin() + 4;
+ auto last = v.end() - 1;
+
+ VERIFY( std::erase(v, 6) == 1 );
+
+ VERIFY(before._M_dereferenceable());
+ VERIFY(last._M_singular());
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++20 } }
+// { dg-add-options no_pch }
+
+#include <debug/vector>
+#include <testsuite_hooks.h>
+
+using __gnu_debug::vector;
+
+void test01()
+{
+ vector<int> v;
+
+ for (int i = 0; i != 10; ++i)
+ v.push_back(i);
+
+ auto before = v.begin() + 4;
+ auto last = v.end() -1;
+
+ VERIFY( std::erase(v, 6) == 1 );
+
+ VERIFY(before._M_dereferenceable());
+ VERIFY(last._M_singular());
+}
+
+int main()
+{
+ test01();
+ return 0;
+}