xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/copy_if.h (revision 5e801ac66d24704442eba426ed13c3effb8a34e7)
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_BEGIN_NAMESPACE_STD
23 
24 template<class _InputIterator, class _OutputIterator, class _Predicate>
25 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
26 _OutputIterator
27 copy_if(_InputIterator __first, _InputIterator __last,
28         _OutputIterator __result, _Predicate __pred)
29 {
30     for (; __first != __last; ++__first)
31     {
32         if (__pred(*__first))
33         {
34             *__result = *__first;
35             ++__result;
36         }
37     }
38     return __result;
39 }
40 
41 _LIBCPP_END_NAMESPACE_STD
42 
43 #endif // _LIBCPP___ALGORITHM_COPY_IF_H
44