According to this page, there a two definitions of a heap
(used by std::make_heap
, std::is_heap
, etc..) :
Until C++20 :
A random access range [
first
,last
) is a heap with respect to a comparatorcomp
ifbool(comp(first[(i - 1) / 2], first[i]))
isfalse
for all integeri
in (0
,last - first
).
Since C++20 :
A random access range [
first
,last
) is a heap with respect to a comparatorcomp
if the range is a heap with respect tocomp
andstd::identity{}
(the identity projection).
Do you have a simpler definition? For example, when comp
is std::less
? I don't understand the usage.
(0, last - first)
" is an exclusive range - neither 0 norlast - first
are parts of it. They borrowed common math notation - you can see[first, last)
range in the same sentence, which includesfirst
but notlast
. Square brackets mean "including", parens mean "excluding", and they can be matched in any combination. For a more detailed definition, see Wiki.