Update copyright in libstdc++-v3.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / heap / moveable.cc
blobe2a3bbca14b9868345db365737f234f6cff3f80b
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 // { dg-options "-std=gnu++0x -DITERATIONS=5" { target simulator } }
22 // 25.3.6 Heap operations [lib.alg.heap.operations]
24 #undef _GLIBCXX_CONCEPT_CHECKS
26 #include <algorithm>
27 #include <testsuite_hooks.h>
28 #include <testsuite_iterators.h>
29 #include <testsuite_rvalref.h>
31 #ifndef ITERATIONS
32 #define ITERATIONS 9
33 #endif
35 using __gnu_test::test_container;
36 using __gnu_test::random_access_iterator_wrapper;
37 using __gnu_test::rvalstruct;
39 typedef test_container<rvalstruct, random_access_iterator_wrapper> container;
40 typedef test_container<int, random_access_iterator_wrapper> container_ref;
42 void
43 check_make(int* array, int length)
45 bool test __attribute__((unused)) = true;
47 rvalstruct makeheap[9];
48 int makeheap_ref[9];
49 std::copy(array, array + length, makeheap);
50 std::copy(array, array + length, makeheap_ref);
51 container makecon(makeheap, makeheap + length);
52 container_ref makecon_ref(makeheap_ref, makeheap_ref + length);
53 std::make_heap(makecon.begin(), makecon.end());
54 std::make_heap(makecon_ref.begin(), makecon_ref.end());
55 for (int z = 0; z < length; ++z)
56 VERIFY( makeheap[z] == makeheap_ref[z] );
57 VERIFY( std::__is_heap(makecon.begin(), makecon.end()) );
58 for (int z = 0; z < length; ++z)
59 VERIFY( makeheap[z].valid );
62 void
63 check_pop(int* array, int length)
65 bool test __attribute__((unused)) = true;
67 rvalstruct popheap[9];
68 int popheap_ref[9];
69 std::copy(array, array + length, popheap);
70 std::copy(array, array + length, popheap_ref);
71 container popcon(popheap, popheap + length);
72 container_ref popcon_ref(popheap_ref, popheap_ref + length);
73 std::pop_heap(popcon.begin(), popcon.end());
74 std::pop_heap(popcon_ref.begin(), popcon_ref.end());
75 for (int z = 0; z < length; ++z)
76 VERIFY( popheap[z] == popheap_ref[z] );
77 VERIFY( (std::__is_heap(popheap, popheap + length - 1)) );
78 for (int z = 0; z < length; ++z)
79 VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
82 void
83 check_sort(int* array, int length)
85 bool test __attribute__((unused)) = true;
87 rvalstruct sortheap[9];
88 int sortheap_ref[9];
89 std::copy(array, array + length, sortheap);
90 std::copy(array, array + length, sortheap_ref);
91 container sortcon(sortheap, sortheap + length);
92 container_ref sortcon_ref(sortheap_ref, sortheap_ref + length);
93 std::sort_heap(sortcon.begin(), sortcon.end());
94 std::sort_heap(sortcon_ref.begin(), sortcon_ref.end());
95 for (int z = 0; z < length; ++z)
96 VERIFY( sortheap[z] == sortheap_ref[z] );
97 for (int z = 0; z < length - 1; ++z)
98 VERIFY( sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid );
99 VERIFY( sortheap[length - 1].valid );
102 void
103 check_push(int* array, int pushval, int length)
105 bool test __attribute__((unused)) = true;
107 rvalstruct pushheap[10];
108 int pushheap_ref[10];
109 std::copy(array, array + length, pushheap);
110 std::copy(array, array + length, pushheap_ref);
111 pushheap[length] = pushval;
112 pushheap_ref[length] = pushval;
113 container pushcon(pushheap, pushheap + length + 1);
114 container_ref pushcon_ref(pushheap_ref, pushheap_ref + length + 1);
115 std::push_heap(pushcon.begin(), pushcon.end());
116 std::push_heap(pushcon_ref.begin(), pushcon_ref.end());
117 for (int z = 0; z < length + 1; ++z)
118 VERIFY( pushheap[z] == pushheap_ref[z] );
119 VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
120 for (int z = 0; z < length + 1; ++z)
121 VERIFY( pushheap[z].valid );
124 void
125 test01()
127 int array[9];
128 for (int i = 1; i < ITERATIONS; ++i)
130 for(int z = 0; z < i; ++z)
131 array[z] = z;
132 while (std::next_permutation(array, array + i))
134 check_make(array, i);
135 if (std::__is_heap(array, array + i))
137 check_pop(array, i);
138 check_sort(array, i);
139 for (int pushval = -1; pushval <= i; ++pushval)
140 check_push(array, pushval, i);
147 main()
149 test01();
150 return 0;