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// push_heap(Iter first, Iter last);
15
16#include <algorithm>
17#include <cassert>
18#include <functional>
19
20#include "test_macros.h"
21#include "test_iterators.h"
22#include "MoveOnly.h"
23
24template<class T, class Iter>
25TEST_CONSTEXPR_CXX20 bool test()
26{
27 T orig[15] = {3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9};
28 T work[15] = {3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9};
29 for (int i = 1; i < 15; ++i) {
30 std::push_heap(Iter(work), Iter(work+i));
31 assert(std::is_permutation(work, work+i, orig));
32 assert(std::is_heap(work, work+i));
33 }
34
35 {
36 T input[] = {1, 3, 2, 5, 4};
37 std::push_heap(Iter(input), Iter(input + 1)); assert(input[0] == 1);
38 std::push_heap(Iter(input), Iter(input + 2)); assert(input[0] == 3);
39 std::push_heap(Iter(input), Iter(input + 3)); assert(input[0] == 3);
40 std::push_heap(Iter(input), Iter(input + 4)); assert(input[0] == 5);
41 std::push_heap(Iter(input), Iter(input + 5)); assert(input[0] == 5);
42 assert(std::is_heap(input, input + 5));
43 }
44 return true;
45}
46
47int main(int, char**)
48{
49 test<int, random_access_iterator<int*> >();
50 test<int, int*>();
51
52#if TEST_STD_VER >= 11
53 test<MoveOnly, random_access_iterator<MoveOnly*>>();
54 test<MoveOnly, MoveOnly*>();
55#endif
56
57#if TEST_STD_VER >= 20
58 static_assert(test<int, random_access_iterator<int*>>());
59 static_assert(test<int, int*>());
60 static_assert(test<MoveOnly, random_access_iterator<MoveOnly*>>());
61 static_assert(test<MoveOnly, MoveOnly*>());
62#endif
63
64 return 0;
65}
66

source code of libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp