1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_COPY_IF_H
10 #define _LIBCPP___ALGORITHM_COPY_IF_H
13 #include <__functional/identity.h>
14 #include <__type_traits/invoke.h>
15 #include <__utility/move.h>
16 #include <__utility/pair.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
23 #include <__undef_macros>
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _InIter
, class _Sent
, class _OutIter
, class _Proj
, class _Pred
>
28 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair
<_InIter
, _OutIter
>
29 __copy_if(_InIter __first
, _Sent __last
, _OutIter __result
, _Pred
& __pred
, _Proj
& __proj
) {
30 for (; __first
!= __last
; ++__first
) {
31 if (std::__invoke(__pred
, std::__invoke(__proj
, *__first
))) {
36 return std::make_pair(std::move(__first
), std::move(__result
));
39 template <class _InputIterator
, class _OutputIterator
, class _Predicate
>
40 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
41 copy_if(_InputIterator __first
, _InputIterator __last
, _OutputIterator __result
, _Predicate __pred
) {
43 return std::__copy_if(__first
, __last
, __result
, __pred
, __proj
).second
;
46 _LIBCPP_END_NAMESPACE_STD
50 #endif // _LIBCPP___ALGORITHM_COPY_IF_H