1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_ERASE_H
10#define _LIBCPP___VECTOR_ERASE_H
11
12#include <__algorithm/remove.h>
13#include <__algorithm/remove_if.h>
14#include <__config>
15#include <__fwd/vector.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24#if _LIBCPP_STD_VER >= 20
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <class _Tp, class _Allocator, class _Up>
29_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
30erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
31 auto __old_size = __c.size();
32 __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
33 return __old_size - __c.size();
34}
35
36template <class _Tp, class _Allocator, class _Predicate>
37_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
38erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
39 auto __old_size = __c.size();
40 __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
41 return __old_size - __c.size();
42}
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP_STD_VER >= 20
47
48_LIBCPP_POP_MACROS
49
50#endif // _LIBCPP___VECTOR_ERASE_H
51