]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.modifying.operations / alg.partitions / partition_copy.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template <class InputIterator, class OutputIterator1,
13 //           class OutputIterator2, class Predicate>
14 //     constexpr pair<OutputIterator1, OutputIterator2>     // constexpr after C++17
15 //     partition_copy(InputIterator first, InputIterator last,
16 //                    OutputIterator1 out_true, OutputIterator2 out_false,
17 //                    Predicate pred);
18
19 #include <algorithm>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "test_iterators.h"
24
25 struct is_odd
26 {
27     TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
28 };
29
30 #if TEST_STD_VER > 17
31 TEST_CONSTEXPR bool test_constexpr() {
32     int ia[] = {1, 3, 5, 2, 4, 6};
33     int r1[10] = {0};
34     int r2[10] = {0};
35
36     auto p = std::partition_copy(std::begin(ia), std::end(ia),
37                     std::begin(r1), std::begin(r2), is_odd());
38
39     return std::all_of(std::begin(r1), p.first, is_odd())
40         && std::all_of(p.first, std::end(r1), [](int a){return a == 0;})
41         && std::none_of(std::begin(r2), p.second, is_odd())
42         && std::all_of(p.second, std::end(r2), [](int a){return a == 0;})
43            ;
44     }
45 #endif
46
47 int main()
48 {
49     {
50         const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
51         int r1[10] = {0};
52         int r2[10] = {0};
53         typedef std::pair<output_iterator<int*>,  int*> P;
54         P p = std::partition_copy(input_iterator<const int*>(std::begin(ia)),
55                                   input_iterator<const int*>(std::end(ia)),
56                                   output_iterator<int*>(r1), r2, is_odd());
57         assert(p.first.base() == r1 + 4);
58         assert(r1[0] == 1);
59         assert(r1[1] == 3);
60         assert(r1[2] == 5);
61         assert(r1[3] == 7);
62         assert(p.second == r2 + 4);
63         assert(r2[0] == 2);
64         assert(r2[1] == 4);
65         assert(r2[2] == 6);
66         assert(r2[3] == 8);
67     }
68
69 #if TEST_STD_VER > 17
70     static_assert(test_constexpr());
71 #endif
72 }