xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/partition_copy.h (revision e9e8876a4d6afc1ad5315faaa191b25121a813d7)
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 
9 #ifndef _LIBCPP___ALGORITHM_PARTITION_COPY_H
10 #define _LIBCPP___ALGORITHM_PARTITION_COPY_H
11 
12 #include <__config>
13 #include <__iterator/iterator_traits.h>
14 #include <utility> // pair
15 
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #pragma GCC system_header
18 #endif
19 
20 _LIBCPP_PUSH_MACROS
21 #include <__undef_macros>
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 template <class _InputIterator, class _OutputIterator1,
26           class _OutputIterator2, class _Predicate>
27 _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_OutputIterator1, _OutputIterator2>
28 partition_copy(_InputIterator __first, _InputIterator __last,
29                _OutputIterator1 __out_true, _OutputIterator2 __out_false,
30                _Predicate __pred)
31 {
32     for (; __first != __last; ++__first)
33     {
34         if (__pred(*__first))
35         {
36             *__out_true = *__first;
37             ++__out_true;
38         }
39         else
40         {
41             *__out_false = *__first;
42             ++__out_false;
43         }
44     }
45     return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
46 }
47 
48 _LIBCPP_END_NAMESPACE_STD
49 
50 _LIBCPP_POP_MACROS
51 
52 #endif // _LIBCPP___ALGORITHM_PARTITION_COPY_H
53