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
and
std::identity{}
(the identity projection).
Of course, first[(i - 1) / 2]
as no meaning for i = 0
, so it seems that there is a mistake in the definition.
Do you have a simpler definition? For example, when comp
is std::less
? I don’t understand the usage.