brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ffea621 Raw
51 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_COPY_IF_H10#define _LIBCPP___ALGORITHM_COPY_IF_H11 12#include <__config>13#include <__functional/identity.h>14#include <__type_traits/invoke.h>15#include <__utility/move.h>16#include <__utility/pair.h>17 18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19#  pragma GCC system_header20#endif21 22_LIBCPP_PUSH_MACROS23#include <__undef_macros>24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27template <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))) {32      *__result = *__first;33      ++__result;34    }35  }36  return std::make_pair(std::move(__first), std::move(__result));37}38 39template <class _InputIterator, class _OutputIterator, class _Predicate>40inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator41copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {42  __identity __proj;43  return std::__copy_if(__first, __last, __result, __pred, __proj).second;44}45 46_LIBCPP_END_NAMESPACE_STD47 48_LIBCPP_POP_MACROS49 50#endif // _LIBCPP___ALGORITHM_COPY_IF_H51