Merged revision 156805 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / partition / moveable.cc
blobab5732019419bacba4275400158f48994319678a
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 25.2.12 [lib.alg.partitions] Partitions.
23 #undef _GLIBCXX_CONCEPT_CHECKS
25 // XXX FIXME: parallel-mode should deal correctly with moveable-only types
26 // per C++0x, at minimum smoothly fall back to serial.
27 #undef _GLIBCXX_PARALLEL
29 #include <algorithm>
30 #include <functional>
31 #include <testsuite_hooks.h>
32 #include <testsuite_rvalref.h>
33 #include <testsuite_iterators.h>
35 using __gnu_test::test_container;
36 using __gnu_test::forward_iterator_wrapper;
37 using __gnu_test::bidirectional_iterator_wrapper;
38 using __gnu_test::rvalstruct;
40 typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
41 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
43 bool test __attribute__((unused)) = true;
45 const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
46 const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
47 const int N = sizeof(A) / sizeof(int);
49 struct Pred
51 bool
52 operator()(const rvalstruct& x) const
53 { return (x.val % 2) == 0; }
56 // 25.2.12 partition()
57 void
58 test01()
60 using std::partition;
62 rvalstruct farray[N];
63 rvalstruct barray[N];
65 std::copy(A, A + N, farray);
66 std::copy(A, A + N, barray);
68 Fcontainer fcon(farray, farray + N);
69 Bcontainer bcon(barray, barray + N);
71 Pred pred;
73 VERIFY(partition(fcon.begin(), fcon.end(), pred).ptr - farray == N/2);
74 for (const rvalstruct* i = farray; i < farray+N/2; ++i)
75 VERIFY(pred(*i));
77 for (const rvalstruct* i = farray+N/2; i < farray + N; ++i)
78 VERIFY(!pred(*i));
80 VERIFY(partition(bcon.begin(), bcon.end(), pred).ptr - barray == N/2);
82 for (const rvalstruct* i = barray; i < barray+N/2; ++i)
83 VERIFY(pred(*i));
84 for (const rvalstruct* i = barray+N/2; i < barray + N; ++i)
85 VERIFY(!pred(*i));
88 int
89 main()
91 test01();
92 return 0;