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
28 template <class _Tp, class _Allocator, class _Up>
29 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
erase(vector<_Tp,_Allocator> & __c,const _Up & __v)30 erase(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
36 template <class _Tp, class _Allocator, class _Predicate>
37 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
erase_if(vector<_Tp,_Allocator> & __c,_Predicate __pred)38 erase_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