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___ALGORITHM_COPY_IF_H
10 #define _LIBCPP___ALGORITHM_COPY_IF_H
11 
12 #include <__config>
13 #include <__algorithm/unwrap_iter.h>
14 #include <__iterator/iterator_traits.h>
15 #include <cstring>
16 #include <type_traits>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #pragma GCC system_header
20 #endif
21 
22 _LIBCPP_PUSH_MACROS
23 #include <__undef_macros>
24 
25 _LIBCPP_BEGIN_NAMESPACE_STD
26 
27 template<class _InputIterator, class _OutputIterator, class _Predicate>
28 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
29 _OutputIterator
30 copy_if(_InputIterator __first, _InputIterator __last,
31         _OutputIterator __result, _Predicate __pred)
32 {
33     for (; __first != __last; ++__first)
34     {
35         if (__pred(*__first))
36         {
37             *__result = *__first;
38             ++__result;
39         }
40     }
41     return __result;
42 }
43 
44 _LIBCPP_END_NAMESPACE_STD
45 
46 _LIBCPP_POP_MACROS
47 
48 #endif // _LIBCPP___ALGORITHM_COPY_IF_H
49