OSDN Git Service

* testsuite/*: Fix copying permission statements.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 25_algorithms / partition / moveable.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
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.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
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/>.
20
21 // 25.2.12 [lib.alg.partitions] Partitions.
22
23 #undef _GLIBCXX_CONCEPT_CHECKS
24
25 #include <algorithm>
26 #include <functional>
27 #include <testsuite_hooks.h>
28 #include <testsuite_rvalref.h>
29 #include <testsuite_iterators.h>
30
31 using __gnu_test::test_container;
32 using __gnu_test::forward_iterator_wrapper;
33 using __gnu_test::bidirectional_iterator_wrapper;
34 using __gnu_test::rvalstruct;
35
36 typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
37 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
38
39 bool test __attribute__((unused)) = true;
40
41 const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
42 const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
43 const int N = sizeof(A) / sizeof(int);
44
45 struct Pred
46 {
47     bool
48     operator()(const rvalstruct& x) const
49     { return (x.val % 2) == 0; }
50 };
51
52 // 25.2.12 partition()
53 void
54 test01()
55 {
56   using std::partition;
57
58   rvalstruct farray[N];   
59   rvalstruct barray[N];
60
61   std::copy(A, A + N, farray);
62   std::copy(A, A + N, barray);
63
64   Fcontainer fcon(farray, farray + N);
65   Bcontainer bcon(barray, barray + N);  
66
67   Pred pred;
68
69   VERIFY(partition(fcon.begin(), fcon.end(), pred).ptr - farray == N/2); 
70   for (const rvalstruct* i = farray; i < farray+N/2; ++i) 
71     VERIFY(pred(*i));
72
73   for (const rvalstruct* i = farray+N/2; i < farray + N; ++i) 
74     VERIFY(!pred(*i));
75
76   VERIFY(partition(bcon.begin(), bcon.end(), pred).ptr - barray == N/2); 
77
78   for (const rvalstruct* i = barray; i < barray+N/2; ++i) 
79     VERIFY(pred(*i));
80   for (const rvalstruct* i = barray+N/2; i < barray + N; ++i) 
81     VERIFY(!pred(*i));
82 }
83
84 int
85 main()
86 {
87   test01();
88   return 0;
89 }