1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <algorithm> |
10 | |
11 | // template<RandomAccessIterator Iter> |
12 | // requires ShuffleIterator<Iter> && LessThanComparable<Iter::value_type> |
13 | // constexpr void // constexpr in C++20 |
14 | // make_heap(Iter first, Iter last); |
15 | |
16 | #include <algorithm> |
17 | #include <cassert> |
18 | |
19 | #include "test_macros.h" |
20 | #include "test_iterators.h" |
21 | #include "MoveOnly.h" |
22 | |
23 | template<class T, class Iter> |
24 | TEST_CONSTEXPR_CXX20 bool test() |
25 | { |
26 | int orig[15] = {3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9}; |
27 | T work[15] = {3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9}; |
28 | for (int n = 0; n < 15; ++n) { |
29 | std::make_heap(Iter(work), Iter(work+n)); |
30 | assert(std::is_heap(work, work+n)); |
31 | assert(std::is_permutation(work, work+n, orig)); |
32 | std::copy(orig, orig+n, work); |
33 | } |
34 | |
35 | { |
36 | T input[] = {3, 4, 1, 2, 5}; |
37 | std::make_heap(Iter(input), Iter(input + 5)); |
38 | assert(std::is_heap(input, input + 5)); |
39 | std::pop_heap(input, input + 5); assert(input[4] == 5); |
40 | std::pop_heap(input, input + 4); assert(input[3] == 4); |
41 | std::pop_heap(input, input + 3); assert(input[2] == 3); |
42 | std::pop_heap(input, input + 2); assert(input[1] == 2); |
43 | std::pop_heap(input, input + 1); assert(input[0] == 1); |
44 | } |
45 | return true; |
46 | } |
47 | |
48 | int main(int, char**) |
49 | { |
50 | test<int, random_access_iterator<int*> >(); |
51 | test<int, int*>(); |
52 | |
53 | #if TEST_STD_VER >= 11 |
54 | test<MoveOnly, random_access_iterator<MoveOnly*>>(); |
55 | test<MoveOnly, MoveOnly*>(); |
56 | #endif |
57 | |
58 | #if TEST_STD_VER >= 20 |
59 | static_assert(test<int, random_access_iterator<int*>>()); |
60 | static_assert(test<int, int*>()); |
61 | static_assert(test<MoveOnly, random_access_iterator<MoveOnly*>>()); |
62 | static_assert(test<MoveOnly, MoveOnly*>()); |
63 | #endif |
64 | |
65 | return 0; |
66 | } |
67 | |