partition_copy.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef _LIBCPP___ALGORITHM_PARTITION_COPY_H
  9. #define _LIBCPP___ALGORITHM_PARTITION_COPY_H
  10. #include <__config>
  11. #include <__iterator/iterator_traits.h>
  12. #include <__utility/pair.h>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. template <class _InputIterator, class _OutputIterator1,
  18. class _OutputIterator2, class _Predicate>
  19. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2>
  20. partition_copy(_InputIterator __first, _InputIterator __last,
  21. _OutputIterator1 __out_true, _OutputIterator2 __out_false,
  22. _Predicate __pred)
  23. {
  24. for (; __first != __last; ++__first)
  25. {
  26. if (__pred(*__first))
  27. {
  28. *__out_true = *__first;
  29. ++__out_true;
  30. }
  31. else
  32. {
  33. *__out_false = *__first;
  34. ++__out_false;
  35. }
  36. }
  37. return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
  38. }
  39. _LIBCPP_END_NAMESPACE_STD
  40. #endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H