late:cpp/algorithm/dsc_merge&action=edit)  
[ ranges::merge  ](/w/cpp/algorithm/ranges/merge "cpp/algorithm/ranges/merge") (C++20)  |  merges two sorted ranges   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_merge&action=edit)  
[ inplace_merge  ](/w/cpp/algorithm/inplace_merge "cpp/algorithm/inplace merge") |  merges two ordered ranges in-place   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/dsc_inplace_merge&action=edit)  
[ ranges::inplace_merge  ](/w/cpp/algorithm/ranges/inplace_merge "cpp/algorithm/ranges/inplace merge") (C++20)  |  merges two ordered ranges in-place   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_inplace_merge&action=edit)  
  
####  [ [ edit ](/mwiki/index.php?title=cpp/algorithm&action=edit&section=22
"Edit section: Heap operations") ]  Heap operations

A random access [ range ](/w/cpp/iterator#Ranges "cpp/iterator") ` [ ` first  ` , ` last  ` ) ` is a _heap with respect to a comparator comp  _ if  bool  (  comp  (  first  [  (  i  \-  1  )  /  2  ]  , first  [  i  ]  )  )  is  false  for all integer  i  in ` ( ` ​  0  ​  ` , ` last  \-  first  ` ) ` .  |  (until C++20)   
---|---  
A random access [ range ](/w/cpp/iterator#Ranges "cpp/iterator") ` [ ` first
` , ` last  ` ) ` is a _heap with respect to comp  and  proj  _ for a
comparator  comp  and projection  proj  if  bool  (  [ std::  invoke
](http://en.cppreference.com/w/cpp/utility/functional/invoke) (  comp, [ std::
invoke  ](http://en.cppreference.com/w/cpp/utility/functional/invoke) (  proj,
first  [  (  i  \-  1  )  /  2  ]  )  ,  
[ std::  invoke  ](http://en.cppreference.com/w/cpp/utility/functional/invoke) (  proj, first  [  i  ]  )  )  is  false  for all integer  i  in ` ( ` ​  0  ​  ` , ` last  \-  first  ` ) ` .  A random access range ` [ ` first  ` , ` last  ` ) ` is a _heap with respect to a comparator comp  _ if the range is a heap with respect to  comp  and  [ std::  identity  ](http://en.cppreference.com/w/cpp/utility/functional/identity) {  }  (the identity projection).  |  (since C++20)   
  
A heap can be created by  [ std::make_heap ](/w/cpp/algorithm/make_heap
"cpp/algorithm/make heap") and  [ ranges::make_heap
](/w/cpp/algorithm/ranges/make_heap "cpp/algorithm/ranges/make heap") (since
C++20)  .

For more properties of heap, see [ max heap
](https://en.wikipedia.org/wiki/Binary_heap "enwiki:Binary heap") .

  

Defined in header ` [ <algorithm> ](/w/cpp/header/algorithm
"cpp/header/algorithm") `  
---  
[ push_heap  ](/w/cpp/algorithm/push_heap "cpp/algorithm/push heap") |  adds an element to a max heap   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/dsc_push_heap&action=edit)  
[ ranges::push_heap  ](/w/cpp/algorithm/ranges/push_heap "cpp/algorithm/ranges/push heap") (C++20)  |  adds an element to a max heap   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_push_heap&action=edit)  
[ pop_heap  ](/w/cpp/algorithm/pop_heap "cpp/algorithm/pop heap") |  removes the largest element from a max heap   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/dsc_pop_heap&action=edit)  
[ ranges::pop_heap  ](/w/cpp/algorithm/ranges/pop_heap "cpp/algorithm/ranges/pop heap") (C++20)  |  removes the largest element from a max heap   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/ranges/dsc_pop_heap&action=edit)  
[ make_heap  ](/w/cpp/algorithm/make_heap "cpp/algorithm/make heap") |  creates a max heap out of a range of elements   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/algorithm/dsc_make_heap&action=edit)  
[ ranges::make_heap  ](/w/cpp/algorithm/ranges/make_heap "cpp/algorithm/ranges/m