xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/remove_if.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
2fe6060f1SDimitry Andric //
3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fe6060f1SDimitry Andric //
7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
8fe6060f1SDimitry Andric 
9fe6060f1SDimitry Andric #ifndef _LIBCPP___ALGORITHM_REMOVE_IF_H
10fe6060f1SDimitry Andric #define _LIBCPP___ALGORITHM_REMOVE_IF_H
11fe6060f1SDimitry Andric 
12fe6060f1SDimitry Andric #include <__algorithm/find_if.h>
1304eeddc0SDimitry Andric #include <__config>
1481ad6265SDimitry Andric #include <__utility/move.h>
15fe6060f1SDimitry Andric 
16fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17fe6060f1SDimitry Andric #  pragma GCC system_header
18fe6060f1SDimitry Andric #endif
19fe6060f1SDimitry Andric 
20b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
21b3edf446SDimitry Andric #include <__undef_macros>
22b3edf446SDimitry Andric 
23fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
24fe6060f1SDimitry Andric 
25fe6060f1SDimitry Andric template <class _ForwardIterator, class _Predicate>
26*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
remove_if(_ForwardIterator __first,_ForwardIterator __last,_Predicate __pred)27cb14a3feSDimitry Andric remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
285f757f3fSDimitry Andric   __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
29cb14a3feSDimitry Andric   if (__first != __last) {
30fe6060f1SDimitry Andric     _ForwardIterator __i = __first;
31cb14a3feSDimitry Andric     while (++__i != __last) {
32cb14a3feSDimitry Andric       if (!__pred(*__i)) {
335f757f3fSDimitry Andric         *__first = std::move(*__i);
34fe6060f1SDimitry Andric         ++__first;
35fe6060f1SDimitry Andric       }
36fe6060f1SDimitry Andric     }
37fe6060f1SDimitry Andric   }
38fe6060f1SDimitry Andric   return __first;
39fe6060f1SDimitry Andric }
40fe6060f1SDimitry Andric 
41fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
42fe6060f1SDimitry Andric 
43b3edf446SDimitry Andric _LIBCPP_POP_MACROS
44b3edf446SDimitry Andric 
45fe6060f1SDimitry Andric #endif // _LIBCPP___ALGORITHM_REMOVE_IF_H
46