95d500618798c34c006d837f20a616b1b5d61ab3
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 25_algorithms / stable_partition / moveable.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 25.2.12 [lib.alg.partitions] Partitions.
21
22 #include <algorithm>
23 #include <functional>
24 #include <testsuite_hooks.h>
25 #include <testsuite_iterators.h>
26 #include <testsuite_rvalref.h>
27
28 using __gnu_test::test_container;
29 using __gnu_test::random_access_iterator_wrapper;
30 using __gnu_test::rvalstruct;
31
32 typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
33
34 const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
35 const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
36 const int N = sizeof(A) / sizeof(int);
37
38 // Check that starting with a true predicate works too. (PR52822)
39 const int A2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
40 const int B2[] = {2, 4, 6, 8, 10, 12, 14, 16, 3, 5, 7, 9, 11, 13, 15, 17};
41 const int N2 = sizeof(A2) / sizeof(int);
42
43 struct Pred
44 {
45   bool
46   operator()(const rvalstruct& x) const
47   { return (x.val % 2) == 0; }
48 };
49
50 // 25.2.12 stable_partition(), starting with a false predicate.
51 void
52 test01()
53 {
54   bool test __attribute__((unused)) = true;
55
56   rvalstruct s1[N];
57   std::copy(A, A + N, s1);
58   Container con(s1, s1 + N);
59
60   std::stable_partition(con.begin(), con.end(), Pred());
61   VERIFY( std::equal(s1, s1 + N, B) );
62 }
63
64 // 25.2.12 stable_partition(), starting with a true predicate.
65 void
66 test02()
67 {
68   bool test __attribute__((unused)) = true;
69
70   rvalstruct s1[N2];
71   std::copy(A2, A2 + N2, s1);
72   Container con(s1, s1 + N2);
73
74   std::stable_partition(con.begin(), con.end(), Pred());
75   VERIFY( std::equal(s1, s1 + N2, B2) );
76 }
77
78 int
79 main()
80 {
81   test01();
82   test02();
83   return 0;
84 }