]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/partition_copy/1.cc
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / partition_copy / 1.cc
CommitLineData
688a7a07
PC
1// { dg-options "-std=gnu++0x" }
2
3// 2008-06-26 Paolo Carlini <paolo.carlini@oracle.com>
4
5// Copyright (C) 2008 Free Software Foundation, Inc.
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
10// Free Software Foundation; either version 2, or (at your option)
11// any later version.
12
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License along
19// with this library; see the file COPYING. If not, write to the Free
20// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21// USA.
22
23#include <algorithm>
24#include <testsuite_hooks.h>
25#include <testsuite_iterators.h>
26
27using __gnu_test::test_container;
28using __gnu_test::input_iterator_wrapper;
29using __gnu_test::output_iterator_wrapper;
30
31typedef test_container<int, input_iterator_wrapper> Icontainer;
32typedef test_container<int, output_iterator_wrapper> Ocontainer;
33int array[] = {0, 5, 2, 1, 3, 4};
34
35bool
36pred(int i)
37{ return i > 2; }
38
39void
40test1()
41{
42 bool test __attribute__((unused)) = true;
43
44 int true_out[1] = { -1 };
45 int false_out[1] = { -1 };
46 Icontainer in_con(array, array);
47 Ocontainer true_out_con(true_out, true_out);
48 Ocontainer false_out_con(false_out, false_out);
49
50 std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
51 std::partition_copy(in_con.begin(), in_con.end(),
52 true_out_con.begin(), false_out_con.begin(), pred);
53
54 VERIFY( res.first.ptr == true_out );
55 VERIFY( res.second.ptr == false_out );
56}
57
58void
59test2()
60{
61 bool test __attribute__((unused)) = true;
62
63 int true_out[1] = { -1 };
64 int false_out[1] = { -1 };
65 Icontainer in_con(array, array + 2);
66 Ocontainer true_out_con(true_out, true_out + 1);
67 Ocontainer false_out_con(false_out, false_out + 1);
68
69 std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
70 std::partition_copy(in_con.begin(), in_con.end(),
71 true_out_con.begin(), false_out_con.begin(), pred);
72
73 VERIFY( res.first.ptr == true_out + 1 );
74 VERIFY( res.second.ptr == false_out + 1 );
75 VERIFY( true_out[0] == 5 );
76 VERIFY( false_out[0] == 0 );
77}
78
79void
80test3()
81{
82 bool test __attribute__((unused)) = true;
83
84 int true_out[3] = { -1, -1, -1 };
85 int false_out[3] = { -1, -1, -1 };
86 Icontainer in_con(array, array + 6);
87 Ocontainer true_out_con(true_out, true_out + 3);
88 Ocontainer false_out_con(false_out, false_out + 3);
89
90 std::pair<output_iterator_wrapper<int>, output_iterator_wrapper<int> > res =
91 std::partition_copy(in_con.begin(), in_con.end(),
92 true_out_con.begin(), false_out_con.begin(), pred);
93
94 VERIFY( res.first.ptr == true_out + 3 );
95 VERIFY( res.second.ptr == false_out + 3 );
96 VERIFY( true_out[0] == 5 && true_out[1] == 3 && true_out[2] == 4 );
97 VERIFY( false_out[0] == 0 && false_out[1] == 2 && false_out[2] == 1 );
98}
99
100int
101main()
102{
103 test1();
104 test2();
105 test3();
106 return 0;
107}