Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:07

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_COPY_IF_H
0010 #define _LIBCPP___ALGORITHM_COPY_IF_H
0011 
0012 #include <__config>
0013 #include <__functional/identity.h>
0014 #include <__type_traits/invoke.h>
0015 #include <__utility/move.h>
0016 #include <__utility/pair.h>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_PUSH_MACROS
0023 #include <__undef_macros>
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 
0027 template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
0028 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0029 __copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
0030   for (; __first != __last; ++__first) {
0031     if (std::__invoke(__pred, std::__invoke(__proj, *__first))) {
0032       *__result = *__first;
0033       ++__result;
0034     }
0035   }
0036   return std::make_pair(std::move(__first), std::move(__result));
0037 }
0038 
0039 template <class _InputIterator, class _OutputIterator, class _Predicate>
0040 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0041 copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
0042   __identity __proj;
0043   return std::__copy_if(__first, __last, __result, __pred, __proj).second;
0044 }
0045 
0046 _LIBCPP_END_NAMESPACE_STD
0047 
0048 _LIBCPP_POP_MACROS
0049 
0050 #endif // _LIBCPP___ALGORITHM_COPY_IF_H