partition_copy.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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, class _OutputIterator2, class _Predicate>
  18. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_OutputIterator1, _OutputIterator2> partition_copy(
  19. _InputIterator __first,
  20. _InputIterator __last,
  21. _OutputIterator1 __out_true,
  22. _OutputIterator2 __out_false,
  23. _Predicate __pred) {
  24. for (; __first != __last; ++__first) {
  25. if (__pred(*__first)) {
  26. *__out_true = *__first;
  27. ++__out_true;
  28. } else {
  29. *__out_false = *__first;
  30. ++__out_false;
  31. }
  32. }
  33. return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
  34. }
  35. _LIBCPP_END_NAMESPACE_STD
  36. #endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H