[push.heap] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#push.heap) ### 26.8.8 Heap operations [[alg.heap.operations]](alg.heap.operations#push.heap) #### 26.8.8.2 push_heap [push.heap] [🔗](#lib:push_heap) `template constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last); template constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); template<[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Comp = ranges::less, class Proj = identity> requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]") constexpr I ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {}); template<[random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]") R, class Comp = ranges::less, class Proj = identity> requires [sortable](alg.req.sortable#concept:sortable "24.3.7.8 Concept sortable [alg.req.sortable]"), Comp, Proj> constexpr borrowed_iterator_t ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {}); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10924) Let comp be less{} and proj be identity{} for the overloads with no parameters by those names[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10929) *Preconditions*: The range [first, last - 1) is a valid heap with respect to comp and proj[.](#2.sentence-1) For the overloads in namespace std,RandomAccessIterator meets the [*Cpp17ValueSwappable*](swappable.requirements#:Cpp17ValueSwappable "16.4.4.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")) and the type of *first meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and the [*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements"))[.](#2.sentence-2) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10940) *Effects*: Places the value in the location last - 1 into the resulting heap [first, last)[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10945) *Returns*: last for the overloads in namespace ranges[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10949) *Complexity*: At most log(last - first) comparisons and twice as many projections[.](#5.sentence-1)