• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //     pair<OutputIterator1, OutputIterator2>
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_iterators.h"
23 
24 struct is_odd
25 {
operator ()is_odd26     bool operator()(const int& i) const {return i & 1;}
27 };
28 
main()29 int main()
30 {
31     {
32         const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
33         int r1[10] = {0};
34         int r2[10] = {0};
35         typedef std::pair<output_iterator<int*>,  int*> P;
36         P p = std::partition_copy(input_iterator<const int*>(std::begin(ia)),
37                                   input_iterator<const int*>(std::end(ia)),
38                                   output_iterator<int*>(r1), r2, is_odd());
39         assert(p.first.base() == r1 + 4);
40         assert(r1[0] == 1);
41         assert(r1[1] == 3);
42         assert(r1[2] == 5);
43         assert(r1[3] == 7);
44         assert(p.second == r2 + 4);
45         assert(r2[0] == 2);
46         assert(r2[1] == 4);
47         assert(r2[2] == 6);
48         assert(r2[3] == 8);
49     }
50 }
51