Merged revisions 195034,195219,195245,195357,195374,195428,195599,195673,195809 via...
[official-gcc.git] / main / libstdc++-v3 / testsuite / 25_algorithms / partition / moveable.cc
blobee323c055014fa43861d0f28d529dea1a0423ed6
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2005-2013 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.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
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/>.
20 // 25.2.12 [lib.alg.partitions] Partitions.
22 #undef _GLIBCXX_CONCEPT_CHECKS
24 #include <algorithm>
25 #include <functional>
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
28 #include <testsuite_iterators.h>
30 using __gnu_test::test_container;
31 using __gnu_test::forward_iterator_wrapper;
32 using __gnu_test::bidirectional_iterator_wrapper;
33 using __gnu_test::rvalstruct;
35 typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
36 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
38 bool test __attribute__((unused)) = true;
40 const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
41 const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
42 const int N = sizeof(A) / sizeof(int);
44 struct Pred
46 bool
47 operator()(const rvalstruct& x) const
48 { return (x.val % 2) == 0; }
51 // 25.2.12 partition()
52 void
53 test01()
55 using std::partition;
57 rvalstruct farray[N];
58 rvalstruct barray[N];
60 std::copy(A, A + N, farray);
61 std::copy(A, A + N, barray);
63 Fcontainer fcon(farray, farray + N);
64 Bcontainer bcon(barray, barray + N);
66 Pred pred;
68 VERIFY(partition(fcon.begin(), fcon.end(), pred).ptr - farray == N/2);
69 for (const rvalstruct* i = farray; i < farray+N/2; ++i)
70 VERIFY(pred(*i));
72 for (const rvalstruct* i = farray+N/2; i < farray + N; ++i)
73 VERIFY(!pred(*i));
75 VERIFY(partition(bcon.begin(), bcon.end(), pred).ptr - barray == N/2);
77 for (const rvalstruct* i = barray; i < barray+N/2; ++i)
78 VERIFY(pred(*i));
79 for (const rvalstruct* i = barray+N/2; i < barray + N; ++i)
80 VERIFY(!pred(*i));
83 int
84 main()
86 test01();
87 return 0;