]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / algorithms / alg.sorting / alg.heap.operations / pop.heap / pop_heap.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<RandomAccessIterator Iter>
13 //   requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type>
14 //   void
15 //   pop_heap(Iter first, Iter last);
16
17 #include <algorithm>
18 #include <cassert>
19
20 void test(int N)
21 {
22     int* ia = new int [N];
23     for (int i = 0; i < N; ++i)
24         ia[i] = i;
25     std::random_shuffle(ia, ia+N);
26     std::make_heap(ia, ia+N);
27     for (int i = N; i > 0; --i)
28     {
29         std::pop_heap(ia, ia+i);
30         assert(std::is_heap(ia, ia+i-1));
31     }
32     std::pop_heap(ia, ia);
33     delete [] ia;
34 }
35
36 int main()
37 {
38     test(1000);
39 }