C++

'std::is_heap' Is Not a Member of 'std' Fix

std::is_heap lives in one header, <algorithm> - and in the sweep probed here, covering all 106 standard headers in this library's header set, only 6 other headers pull it in on the side, so the textbook <vector> program fails outright. The call itself answers a yes-or-no question - is this range a max heap under the default comparator - returning true for an empty range, a single element, and a real max heap, and false for a plain ascending order, which is a min heap, not a max heap. This name also has a floor its oldest siblings lack: it dates to C++11, so a C++98 build fails with the same wording even with the include in place. This guide pins down the failing shapes, the one suggestion this name earns - in the C++98 transcript only - and the include that fixes the missing-include case by rule.

Written December 3, 2026 · Tested with GCC 13.3.0 · 28 min read

By the end of this guide
  • The error: the include is missing
  • The textbook version fails too - with the same plain line
  • Neighboring headers: 99 fail plainly, and 6 rescue it by accident
  • The fix

Written December 3, 2026

Tested with GCC 13.3.0

What this guide is

std::is_heap is a function template defined in the header <algorithm>. It checks whether a range is a heap and returns true or false: over 9, 5, 8, 1, 3, 7 - every parent at least as large as its children - it returns true. The default check is for a max heap, with respect to operator< before C++20 and std::less{} since C++20; a second form takes a comparator and checks the heap property with respect to that comparator instead. The range needs random-access iterators. The documented cost is linear - O(N) comparisons over a range of length N. The classic call dates to C++11, has an execution-policy overload since C++17, and has been usable in constant expressions since C++20. Its companion std::is_heap_until, also since C++11, returns the past-the-end iterator of the largest prefix that is a heap, which is how the first out-of-order element is located.

Because the function lives in <algorithm> - not in a container's header - 'is_heap' is not a member of 'std' is usually the missing include, and naming the cause is the first step:

  • The #include <algorithm> line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, that second clause rarely saves anyone: in the sweep below, only 6 of the other 105 headers in the library's header set pull the name in on the side, so most files without <algorithm> do reach this error.

For this name the missing include is the usual cause, but it is not the only one. std::is_heap starts at C++11, so a build set to C++98 produces this same wording even with <algorithm> included, as the versions section below shows - and that transcript is the one place this name's diagnostic carries a did you mean tail, naming a heap function that already existed in C++98. The pieces layered on top still have floors of their own - the execution-policy overload needs C++17 and constant-expression use needs C++20 - and those floors belong to the added pieces, not to the classic call.

In the missing-include sweep below, all 99 failing sole-header contexts produce the plain error line alone - no did you mean tail in any of them, no note lines, and no help lines. The reader learns that the name is not a member of std in this file, and the declaring header has to come from knowledge, not from the diagnostic. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the rescue set has only 7 entries, because in this library the name is declared by a header that very little of the library includes.

The error: the include is missing

This program tests 9, 5, 8, 1, 3, 7 as a max heap, but includes only <limits>:

C++
#include <limits>
int main() {
    int a[6] = {9, 5, 8, 1, 3, 7};
    bool b = std::is_heap(a, a + 6);
    return 0;
}
Output
-std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:19: error: 'is_heap' is not a member of 'std'
    4 |     bool b = std::is_heap(a, a + 6);
      |                   ^~~~~~~

Read it in full: one plain error line - no suggestion tail rides on it, there are no note lines, and there are no help lines. Nothing in the diagnostic names <algorithm> or points anywhere at all. The same program with no include at all fails the same way:

Output
-std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:19: error: 'is_heap' is not a member of 'std'
    3 |     bool b = std::is_heap(a, a + 6);
      |                   ^~~~~~~

The textbook version fails too - with the same plain line

The version most often written first - test a vector for the heap property - produces an error in this library, without <algorithm>, and the error is the same bare line:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {9, 5, 8, 1, 3, 7};
    bool b = std::is_heap(v.begin(), v.end());
    std::cout << b << "\n";
    return 0;
}
Output
-std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:19: error: 'is_heap' is not a member of 'std'
    5 |     bool b = std::is_heap(v.begin(), v.end());
      |                   ^~~~~~~

Nothing rescues the call here: <vector> does not pull the algorithm in - in the sweep below it fails for this name, with this same plain line. And there is no suggestion to follow or to ignore: this diagnostic names no other name at all. A program that uses std::is_heap includes <algorithm>, whether or not it happens to compile without it. A sole <algorithm> file makes the point in miniature - the call compiles and runs with nothing else in sight:

Terminal
-std=c++20 i_algorithm.cpp -o i_algorithm_prog
$ ./i_algorithm_prog

Neighboring headers: 99 fail plainly, and 6 rescue it by accident

In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that tests 9, 5, 8, 1, 3, 7 as a max heap and requires the answer true, the outcome splits two ways - the plain failure, or a rescue. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 99 headers all fail with the plain is not a member of 'std' error line - no suggestion tail on that line, no note lines, and no help lines:

  • <any>
  • <array>
  • <atomic>
  • <barrier>
  • <bit>
  • <bitset>
  • <cassert>
  • <ccomplex>
  • <cctype>
  • <cerrno>
  • <cfenv>
  • <cfloat>
  • <charconv>
  • <cinttypes>
  • <ciso646>
  • <climits>
  • <clocale>
  • <cmath>
  • <codecvt>
  • <compare>
  • <complex>
  • <concepts>
  • <condition_variable>
  • <coroutine>
  • <csetjmp>
  • <csignal>
  • <cstdalign>
  • <cstdarg>
  • <cstdbool>
  • <cstddef>
  • <cstdint>
  • <cstdio>
  • <cstdlib>
  • <cstring>
  • <ctgmath>
  • <ctime>
  • <cuchar>
  • <cwchar>
  • <cwctype>
  • <deque>
  • <exception>
  • <expected>
  • <filesystem>
  • <format>
  • <forward_list>
  • <fstream>
  • <future>
  • <initializer_list>
  • <iomanip>
  • <ios>
  • <iosfwd>
  • <iostream>
  • <istream>
  • <iterator>
  • <latch>
  • <limits>
  • <list>
  • <locale>
  • <map>
  • <memory>
  • <memory_resource>
  • <mutex>
  • <new>
  • <numbers>
  • <numeric>
  • <optional>
  • <ostream>
  • <random>
  • <ranges>
  • <ratio>
  • <scoped_allocator>
  • <semaphore>
  • <set>
  • <shared_mutex>
  • <source_location>
  • <span>
  • <spanstream>
  • <sstream>
  • <stack>
  • <stacktrace>
  • <stdexcept>
  • <stdfloat>
  • <stop_token>
  • <streambuf>
  • <string>
  • <string_view>
  • <syncstream>
  • <system_error>
  • <thread>
  • <tuple>
  • <type_traits>
  • <typeindex>
  • <typeinfo>
  • <unordered_map>
  • <unordered_set>
  • <utility>
  • <variant>
  • <vector>
  • <version>

A file with no include at all fails the plain way. Two entries deserve a pause. <limits> fails plainly: the header of the numeric limits declares nothing close enough to this name to trigger a guess, which is why the first section's program shows the bare line. <ranges> fails plainly for the classic name: the C++20 ranges library has its own is-heap name, and it does not bring this one in - that name gets its own section below. And <vector> - the header of the container this call most often tests - fails plainly, as the textbook section above shows.

No failing header in any shape produced a suggestion, a help line, or a different error.

And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:

  • <algorithm>
  • <chrono>
  • <execution>
  • <functional>
  • <queue>
  • <regex>
  • <valarray>

The declaring header in this library sits underneath very little - a time header, a policy header, a function-object header, a container-adaptor header, the regular-expression header, and the numeric-array header - so the rescue set runs to only 6 transitive entries. That is also why the failing set is nearly the whole library here: with 99 of the other 105 headers failing, the missing include shows itself in almost any file that does not name <algorithm>. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and the other 6 rescues are this library version's behavior, not a guarantee.

The fix

Add the header:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {9, 5, 8, 1, 3, 7};
    std::cout << "heap " << std::is_heap(v.begin(), v.end()) << "\n";
    std::vector<int> s = {1, 3, 5, 7, 8, 9};
    std::cout << "sorted " << std::is_heap(s.begin(), s.end()) << "\n";
    return 0;
}
Terminal
-std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
heap 1
sorted 0

One include, <algorithm>, declares the function - and the fixed program prints two lines that carry this name's shape. The first, heap 1, is the heap answer: 9, 5, 8, 1, 3, 7 is a max heap, so the call returns true, printed as 1. The second, sorted 0, is the same question over the ascending order 1, 3, 5, 7, 8, 9: the first element is smaller than its children, so the range is not a max heap and the call returns false. The name is now declared by a header the file names itself, instead of by an internal include of one of the 6 rescuing headers that a different library version is free to rearrange. For a file that does fail - the <limits> shape above, or any other - the same one include is the whole fix for the missing-include error, at every standard level from C++11 up: below that level this name has a floor case of its own, as the versions section below shows.

What the call does: it answers whether the range is a heap under the comparator

The call's whole result is a bool - true when every element's parent satisfies the heap property under the comparator, false at the first violation - and its defining choices are the default comparator's direction and the vacuous cases. The default check is a max-heap check, so an ascending order fails it and a descending order passes it; passing std::greater flips the question to a min-heap check. This program walks the shapes in order:

C++
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> empty;
    std::cout << "empty " << std::is_heap(empty.begin(), empty.end()) << "\n";
    std::vector<int> one = {42};
    std::cout << "single " << std::is_heap(one.begin(), one.end()) << "\n";
    std::vector<int> heap = {9, 5, 8, 1, 3, 7};
    std::cout << "heap " << std::is_heap(heap.begin(), heap.end()) << "\n";
    std::vector<int> sorted = {1, 3, 5, 7, 8, 9};
    std::cout << "sorted " << std::is_heap(sorted.begin(), sorted.end()) << "\n";
    std::vector<int> desc = {9, 8, 7, 5, 3, 1};
    std::cout << "desc " << std::is_heap(desc.begin(), desc.end()) << "\n";
    std::cout << "minheap " << std::is_heap(sorted.begin(), sorted.end(), std::greater<int>()) << "\n";
    std::cout << "heapgreater " << std::is_heap(heap.begin(), heap.end(), std::greater<int>()) << "\n";
    std::vector<int> broken = {9, 5, 8, 1, 10, 7};
    auto u = std::is_heap_until(broken.begin(), broken.end());
    std::cout << "until " << (u - broken.begin()) << " value " << *u << "\n";
    auto uh = std::is_heap_until(heap.begin(), heap.end());
    std::cout << "untilheap " << (uh == heap.end() ? "end" : "mid") << "\n";
    auto us = std::is_heap_until(sorted.begin(), sorted.end());
    std::cout << "untilsorted " << (us - sorted.begin()) << "\n";
    return 0;
}
Terminal
-std=c++20 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
empty 1
single 1
heap 1
sorted 0
desc 1
minheap 1
heapgreater 0
until 4 value 10
untilheap end
untilsorted 1

Read in order: the empty line reports 1 - over an empty range there is no parent-child pair to violate the property, so the answer is true. The single line also reports 1: one element alone is a heap. The heap line reports 1: over 9, 5, 8, 1, 3, 7 every parent is at least as large as its children. The sorted line reports 0: over 1, 3, 5, 7, 8, 9 the root 1 is smaller than its children 3 and 5, so the range is not a max heap - ascending order is the min-heap shape, not the max-heap shape. The desc line reports 1: the descending order 9, 8, 7, 5, 3, 1 does satisfy the max-heap property. The minheap line reports 1: the same ascending order under std::greater<int> - the min-heap check - passes, because under that comparator each parent must be no larger than its children, and it is. The heapgreater line reports 0: the max heap under that same flipped comparator fails. The until line reports 4 value 10: std::is_heap_until over 9, 5, 8, 1, 10, 7 returns the iterator at position 4, pointing at the value 10 - the first element that breaks the heap, because its parent at position 1 holds 5 and 10 outranks it; the heap prefix is the four elements before it. The untilheap line reports end: over a full heap the largest heap prefix is the whole range, so the returned iterator is the end. And the untilsorted line reports 1: over the ascending order the heap prefix is just the first element, because the second element already outranks its parent.

The cost rule is the documented bound: with a range of length N, the call makes O(N) comparisons - one linear pass over the range, however the elements are arranged.

Versions: the floor is C++11 - C++98 fails with this same wording

This call does have a floor inside the probed set. std::is_heap dates to C++11 - the cppreference page marks both classic overloads since C++11. The fixed programs in this guide are compiled as C++20, but the name is older than that: with <algorithm> included, the same program compiled as C++11 compiles and runs, printing 1 - the heap answer - and as C++14, C++17, C++20, and C++23 the same way. Compiled as C++98, the same program fails, because the name did not exist yet at that standard:

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[6] = {9, 5, 8, 1, 3, 7};
    bool b = std::is_heap(a, a + 6);
    std::cout << b << "\n";
    return 0;
}
Output
-std=c++98 c_version98.cpp -o c_version98_prog
c_version98.cpp: In function 'int main()':
c_version98.cpp:5:19: error: 'is_heap' is not a member of 'std'; did you mean 'push_heap'?
    5 |     bool b = std::is_heap(a, a + 6);
      |                   ^~~~~~~
      |                   push_heap

So this name's error has two causes, not one: a missing <algorithm>, or a standard below C++11. The C++98 transcript is also the one place this diagnostic carries a suggestion: did you mean 'push_heap'? - and the guess is a real heap function, one that already existed in C++98, but it does a different job: push_heap inserts an element into a heap, it does not test whether a range is one. Read the standard level first when this error appears in an old-standard build, and the include list first everywhere else. A file that includes <algorithm>, builds at C++11 or later, and still sees this error does not have a standard problem; the include is not reaching the file that names the call, or the name in the file is not this name.

The pieces layered on top of the classic call carry their own floors. This name does have an execution-policy overload, since C++17 - and naming the policy with only <algorithm> included fails on the policy's name, not the algorithm's:

C++
#include <algorithm>
#include <vector>
int main() {
    std::vector<int> v = {9, 5, 8, 1, 3, 7};
    bool b = std::is_heap(std::execution::seq, v.begin(), v.end());
    return b ? 0 : 1;
}
Output
-std=c++20 p_policy_algonly.cpp -o p_policy_algonly_prog
p_policy_algonly.cpp: In function 'int main()':
p_policy_algonly.cpp:5:32: error: 'std::execution' has not been declared
    5 |     bool b = std::is_heap(std::execution::seq, v.begin(), v.end());
      |                                ^~~~~~~~~

That wording - has not been declared, naming std::execution - is the missing-header shape, and here adding the header is the whole fix: add <execution> alongside <algorithm>, and the same call compiles and runs, because the policy overload of std::is_heap exists - and the policy form of this name returns the same bool as the classic call:

Terminal
-std=c++20 p_policy_both.cpp -o p_policy_both_prog
$ ./p_policy_both_prog

The policy form belongs to this name, and it carries the C++17 floor. Compiled as C++14, the same two-header program fails on the policy's name again - at that standard the policy names are not there to be declared:

Output
-std=c++14 p_policy_cpp14.cpp -o p_policy_cpp14_prog
p_policy_cpp14.cpp: In function 'int main()':
p_policy_cpp14.cpp:6:32: error: 'std::execution' has not been declared
    6 |     bool b = std::is_heap(std::execution::seq, v.begin(), v.end());
      |                                ^~~~~~~~~

And since C++20 the classic call is also usable in constant expressions - this program's check happens at compile time, and the assertion on the result is part of the build:

C++
#include <algorithm>
#include <array>
constexpr bool check() {
    std::array<int, 6> a{9, 5, 8, 1, 3, 7};
    return std::is_heap(a.begin(), a.end());
}
static_assert(check());
int main() { return 0; }
Terminal
-std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog

Compiled as C++17, the same program fails - the call is not a constant expression there, and the static assertion cannot hold:

Output
-std=c++17 c_constexpr17.cpp -o c_constexpr17_prog
c_constexpr17.cpp: In function 'constexpr bool check()':
c_constexpr17.cpp:5:24: warning: call to non-'constexpr' function 'bool std::is_heap(_RAIter, _RAIter) [with _RAIter = int*]' [-Winvalid-constexpr]
    5 |     return std::is_heap(a.begin(), a.end());
      |            ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/stl_algo.h:61,
                 from /usr/include/c++/13/algorithm:61,
                 from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_heap.h:551:5: note: 'bool std::is_heap(_RAIter, _RAIter) [with _RAIter = int*]' declared here
  551 |     is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~~~~
c_constexpr17.cpp: At global scope:
c_constexpr17.cpp:7:20: error: non-constant condition for static assertion
    7 | static_assert(check());
      |               ~~~~~^~
c_constexpr17.cpp:7:20: error: 'constexpr bool check()' called in a constant expression
c_constexpr17.cpp:3:16: note: 'constexpr bool check()' declared here
    3 | constexpr bool check() {
      |                ^~~~~

So C++11 is the floor for the classic call, C++17 is the floor for the policy form, and C++20 is the floor for constant-expression use - and no standard at any level rescues a missing include.

The neighboring names: seven fail, one compiles outright

The names a reader most often reaches for alongside this one mostly live in <algorithm> too, and in a file whose only include is <vector> this family splits - seven of the eight names fail, and one compiles. std::find, which returns an iterator to the first element equal to a value, fails with a suggestion that points into the ranges library:

Output
-std=c++20 b_find_vector.cpp -o b_find_vector_prog
b_find_vector.cpp: In function 'int main()':
b_find_vector.cpp:4:20: error: 'find' is not a member of 'std'; did you mean 'std::ranges::find'?
    4 |     auto it = std::find(v.begin(), v.end(), 3);
      |                    ^~~~
In file included from /usr/include/c++/13/tuple:44,
                 from /usr/include/c++/13/bits/uses_allocator_args.h:38,
                 from /usr/include/c++/13/bits/memory_resource.h:41,
                 from /usr/include/c++/13/vector:80,
                 from b_find_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:499:30: note: 'std::ranges::find' declared here
  499 |   inline constexpr __find_fn find{};
      |                              ^~~~

std::copy, which copies a range into another range, is the split: in this library a sole <vector> file compiles it outright, with no <algorithm> anywhere - the container header pulls the name in on the side here, as this library version's behavior, not as a rule:

Terminal
-std=c++20 b_copy_vector.cpp -o b_copy_vector_prog
$ ./b_copy_vector_prog

std::transform, which applies a function to a range and stores the results in a destination range, fails with the plain error:

Output
-std=c++20 b_transform_vector.cpp -o b_transform_vector_prog
b_transform_vector.cpp: In function 'int main()':
b_transform_vector.cpp:5:20: error: 'transform' is not a member of 'std'
    5 |     auto it = std::transform(v.begin(), v.end(), dest.begin(), [](int n) { return n * 2; });
      |                    ^~~~~~~~~

std::count, which counts the elements equal to a value, fails with a suggestion that points at a bit-counting function, not at any algorithm:

Output
-std=c++20 b_count_vector.cpp -o b_count_vector_prog
b_count_vector.cpp: In function 'int main()':
b_count_vector.cpp:4:19: error: 'count' is not a member of 'std'; did you mean 'popcount'?
    4 |     auto c = std::count(v.begin(), v.end(), 3);
      |                   ^~~~~
      |                   popcount

std::sort, which orders a range in place, fails with the plain error:

Output
-std=c++20 b_sort_vector.cpp -o b_sort_vector_prog
b_sort_vector.cpp: In function 'int main()':
b_sort_vector.cpp:4:10: error: 'sort' is not a member of 'std'
    4 |     std::sort(v.begin(), v.end());
      |          ^~~~

std::remove, which removes the elements equal to a value by compacting the kept elements forward, fails with a suggestion that points at a different algorithm altogether:

Output
-std=c++20 b_remove_vector.cpp -o b_remove_vector_prog
b_remove_vector.cpp: In function 'int main()':
b_remove_vector.cpp:4:20: error: 'remove' is not a member of 'std'; did you mean 'move'?
    4 |     auto it = std::remove(v.begin(), v.end(), 3);
      |                    ^~~~~~
      |                    move

std::unique, which compacts away consecutive duplicate elements and returns a new logical end, fails with the plain error:

Output
-std=c++20 b_unique_vector.cpp -o b_unique_vector_prog
b_unique_vector.cpp: In function 'int main()':
b_unique_vector.cpp:4:20: error: 'unique' is not a member of 'std'
    4 |     auto it = std::unique(v.begin(), v.end());
      |                    ^~~~~~

While std::partition, which rearranges a range so the elements a predicate matches come first and returns the partition point, fails with the plain error too:

Output
-std=c++20 b_partition_vector.cpp -o b_partition_vector_prog
b_partition_vector.cpp: In function 'int main()':
b_partition_vector.cpp:4:20: error: 'partition' is not a member of 'std'
    4 |     auto it = std::partition(v.begin(), v.end(), [](int n) { return n % 2 == 0; });
      |                    ^~~~~~~~~

This name itself earns no suggestion in any missing-include context probed here, but its neighbors do: one names the ranges form of a neighbor, one names a bit-counting function, and one names a moving algorithm - all three are spelling guesses, and none of them does what the failed name does. The one suggestion this name itself earns rides on the C++98 transcript in the versions section, not on any missing-include transcript. And the one name that compiles, std::copy, compiles by accident of this library's internal includes - the rule for it is the same <algorithm> as for the rest. The failing neighbors are shown here only as neighbors, not re-taught.

The neighboring names, fixed

Together the nine names take one header between them - <algorithm> for all nine, with <vector> covering only the containers they work on. The fixed neighbor program reports all nine operations:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> heap = {9, 5, 8, 1, 3, 7};
    std::cout << "is_heap " << std::is_heap(heap.begin(), heap.end()) << "\n";
    std::vector<int> u = {1, 2, 3, 4, 5, 6};
    auto f = std::find(u.begin(), u.end(), 3);
    std::cout << "find " << (f - u.begin()) << " " << *f << "\n";
    auto c = std::count(u.begin(), u.end(), 3);
    std::cout << "count " << c << "\n";
    std::vector<int> dest(6);
    std::copy(u.begin(), u.end(), dest.begin());
    std::cout << "copy " << dest.front() << " " << dest.back() << "\n";
    std::vector<int> doubled(6);
    std::transform(u.begin(), u.end(), doubled.begin(), [](int n) { return n * 2; });
    std::cout << "transform";
    for (int n : doubled) std::cout << " " << n;
    std::cout << "\n";
    std::vector<int> w = {6, 3, 5, 1, 4, 2};
    std::sort(w.begin(), w.end());
    std::cout << "sort";
    for (int n : w) std::cout << " " << n;
    std::cout << "\n";
    std::vector<int> r = {1, 2, 3, 4, 3, 6};
    auto re = std::remove(r.begin(), r.end(), 3);
    std::cout << "remove";
    for (auto it = r.begin(); it != re; ++it) std::cout << " " << *it;
    std::cout << " end " << (re - r.begin()) << "\n";
    std::vector<int> q = {1, 1, 2, 2, 3, 3};
    auto qe = std::unique(q.begin(), q.end());
    std::cout << "unique";
    for (auto it = q.begin(); it != qe; ++it) std::cout << " " << *it;
    std::cout << " end " << (qe - q.begin()) << "\n";
    std::vector<int> p = {1, 2, 3, 4, 5, 6};
    auto pp = std::partition(p.begin(), p.end(), [](int n) { return n % 2 == 0; });
    std::cout << "partition end " << (pp - p.begin()) << " first";
    for (auto it = p.begin(); it != pp; ++it) std::cout << " " << *it;
    std::cout << "\n";
    return 0;
}
Terminal
-std=c++20 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
is_heap 1
find 2 3
count 1
copy 1 6
transform 2 4 6 8 10 12
sort 1 2 3 4 5 6
remove 1 2 4 6 end 4
unique 1 2 3 end 3
partition end 3 first 6 2 4

Read in order: is_heap reports 1 - 9, 5, 8, 1, 3, 7 is a max heap. find reports position 2 and the value 3 - the first element equal to 3. count reports 1 - one element equals 3. copy reports 1 6 - the destination's first and last elements after the range was copied into it. transform reports 2 4 6 8 10 12 - each element doubled into the destination. sort reports 1 2 3 4 5 6 - the shuffled range 6, 3, 5, 1, 4, 2 put back in order. remove reports 1 2 4 6 end 4 - both elements equal to 3 compacted out of 1, 2, 3, 4, 3, 6, with the new end at position 4. unique reports 1 2 3 end 3 - the consecutive duplicates in 1, 1, 2, 2, 3, 3 compacted away. And partition reports end 3 with the first segment holding the three even values - partition makes no promise about the order inside either segment, so the segment is reported as it came out, not as a sorted result.

A ranges form since C++20, in the same header

C++20 added a ranges form of this name, and the standard declares it in the same header as the classic name. std::ranges::is_heap is a function object in the ranges namespace, declared in <algorithm>, that accepts a whole range - or an iterator-sentinel pair - and answers the same bool: true when the range is a heap under the comparator, false otherwise. Its companion std::ranges::is_heap_until returns the iterator where the heap prefix ends. Compiled as C++20 they answer for the same vectors:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {9, 5, 8, 1, 3, 7};
    std::cout << "ranges " << std::ranges::is_heap(v) << "\n";
    std::vector<int> s = {1, 3, 5, 7, 8, 9};
    std::cout << "rangessorted " << std::ranges::is_heap(s) << "\n";
    auto u = std::ranges::is_heap_until(v);
    std::cout << "rangesuntil " << (u == v.end() ? "end" : "mid") << "\n";
    return 0;
}
Terminal
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
ranges 1
rangessorted 0
rangesuntil end

The ranges line reports 1 - the vector 9, 5, 8, 1, 3, 7 is a max heap. The rangessorted line reports 0: the ascending order is not a max heap, the same answer the classic call gives. The rangesuntil line reports end: over a full heap, std::ranges::is_heap_until returns the range's end, matching the classic companion. Two boundaries keep the forms straight. The ranges form needs C++20: compiled as C++17, that same program fails on the namespace itself, with 'std::ranges' has not been declared:

Output
-std=c++17 r_ranges_cpp17.cpp -o r_ranges_cpp17_prog
r_ranges_cpp17.cpp: In function 'int main()':
r_ranges_cpp17.cpp:6:36: error: 'std::ranges' has not been declared
    6 |     std::cout << "ranges " << std::ranges::is_heap(v) << "\n";
      |                                    ^~~~~~
r_ranges_cpp17.cpp:8:42: error: 'std::ranges' has not been declared
    8 |     std::cout << "rangessorted " << std::ranges::is_heap(s) << "\n";
      |                                          ^~~~~~
r_ranges_cpp17.cpp:9:19: error: 'std::ranges' has not been declared
    9 |     auto u = std::ranges::is_heap_until(v);
      |                   ^~~~~~

And in this library the ranges header does not rescue the ranges form - a file whose only include is <ranges> (with <vector> for the containers) fails for it with a not-a-member error naming the ranges namespace, and a file whose only include is <array> fails for it the same way, both with the plain line alone and no suggestion on either transcript - the classic sweep classification does not transfer to the ranges form, and here the ranges form's own two sole-header probes agree with each other while differing from this name's C++98 transcript, which is where the family's one suggestion for this name lives:

Output
-std=c++20 r_ranges_rangesonly.cpp -o r_ranges_rangesonly_prog
r_ranges_rangesonly.cpp: In function 'int main()':
r_ranges_rangesonly.cpp:5:27: error: 'is_heap' is not a member of 'std::ranges'
    5 |     bool b = std::ranges::is_heap(v);
      |                           ^~~~~~~
Output
-std=c++20 r_ranges_arrayonly.cpp -o r_ranges_arrayonly_prog
r_ranges_arrayonly.cpp: In function 'int main()':
r_ranges_arrayonly.cpp:4:27: error: 'is_heap' is not a member of 'std::ranges'
    4 |     bool b = std::ranges::is_heap(v);
      |                           ^~~~~~~

That is this library version's behavior, not the rule: the header the standard names for both forms is <algorithm>, so a complete program names it - and with only <algorithm> and <vector> included, the ranges call over a vector compiles and runs, as its own probe shows:

Terminal
-std=c++20 r_ranges_algonly_range.cpp -o r_ranges_algonly_range_prog
$ ./r_ranges_algonly_range_prog

The classic name, meanwhile, is not pulled in by the ranges header either: in the sweep probed here, a file whose only include is <ranges> fails for std::is_heap with the plain error line, as the sweep section above lists.

A different wording - and an argument-dependent rescue that depends on the iterators' types

Including <algorithm> is not the only half of the name. Over plain arrays, the unqualified call fails:

C++
#include <algorithm>
int main() {
    int a[6] = {9, 5, 8, 1, 3, 7};
    bool b = is_heap(a, a + 6);
    return 0;
}
Output
-std=c++20 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:4:14: error: 'is_heap' was not declared in this scope
    4 |     bool b = is_heap(a, a + 6);
      |              ^~~~~~~
g_unqualified.cpp:4:14: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:510:1: note:   'std::is_heap'
  510 | is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:1773:33: note:   'std::ranges::is_heap'
 1773 |   inline constexpr __is_heap_fn is_heap{};
      |                                 ^~~~~~~

That wording - was not declared in this scope, with notes pointing at the declarations of both std::is_heap and the ranges form - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::is_heap; adding includes does not bring the name out of namespace std. Swap the arrays for vectors, and the same unqualified call compiles and runs:

C++
#include <algorithm>
#include <vector>
int main() {
    std::vector<int> v = {9, 5, 8, 1, 3, 7};
    bool b = is_heap(v.begin(), v.end());
    return b ? 0 : 1;
}
Terminal
-std=c++20 g_unqualified_vec.cpp -o g_unqualified_vec_prog
$ ./g_unqualified_vec_prog

That compile is argument-dependent lookup at work, not a rule to rely on: the vectors' iterators are std types, so their associated namespace is std, and lookup finds std::is_heap through them. A deque's iterators rescue it the same way - the same unqualified call over a deque compiles and runs:

Terminal
-std=c++20 g_unqualified_deque.cpp -o g_unqualified_deque_prog
$ ./g_unqualified_deque_prog

But the container being a std type is not enough by itself - over a std::array, the same unqualified call fails with the same wording, because in this library a std::array's iterators are plain pointers, and a pointer has no associated namespace:

C++
#include <algorithm>
#include <array>
int main() {
    std::array<int, 6> v{9, 5, 8, 1, 3, 7};
    bool b = is_heap(v.begin(), v.end());
    return 0;
}
Output
-std=c++20 g_unqualified_stdarray.cpp -o g_unqualified_stdarray_prog
g_unqualified_stdarray.cpp: In function 'int main()':
g_unqualified_stdarray.cpp:5:14: error: 'is_heap' was not declared in this scope
    5 |     bool b = is_heap(v.begin(), v.end());
      |              ^~~~~~~
g_unqualified_stdarray.cpp:5:14: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified_stdarray.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:510:1: note:   'std::is_heap'
  510 | is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:1773:33: note:   'std::ranges::is_heap'
 1773 |   inline constexpr __is_heap_fn is_heap{};
      |                                 ^~~~~~~

And with using namespace std; in the file, the qualifier question goes away by a different route - the unqualified call over vectors compiles and runs, because the using-directive brings the name into scope directly:

Terminal
-std=c++20 g_using_namespace.cpp -o g_using_namespace_prog
$ ./g_using_namespace_prog

The pattern across the probed set is exact: the rescue follows the iterator type, not the container's name - class iterators of std containers carry the name in, pointer iterators do not, whatever container stands behind them - and a using-directive bypasses the question entirely. Write the qualifier either way.

The exact rule

  • std::is_heap is declared by #include <algorithm>, and by no other header by rule. In the sweep probed here, 99 of the other 105 headers in the library's header set - among them <limits>, <ranges>, <vector>, <filesystem>, and <string> - do not declare it, and neither does a file with no include at all; the remaining 6 pull it in transitively, as this library version's behavior, not as a guarantee.
  • 'is_heap' is not a member of 'std' has two causes in the contexts probed here: the <algorithm> include is missing and nothing else in the file pulled the name in, or the build is set below C++11, where the name did not exist yet. In the missing-include sweep probed here it comes in one shape: all 99 failing sole headers fail with the plain error line alone - no suggestion tail, no note lines, no help lines, and no different error from any header. The C++98 transcript is the exception that proves the split: with the include in place it fails with the same wording plus the suggestion did you mean 'push_heap'?.
  • In the sweep probed here, 6 headers besides <algorithm> rescue std::is_heap transitively - <chrono>, <execution>, <functional>, <queue>, <regex>, and <valarray> - so a file whose only include is one of those compiles and runs the call without <algorithm>. That is this library version's behavior, not a guarantee - in the probed set, no header besides <algorithm> is required to pull std::is_heap in.
  • The result rules are the documented ones, as the fixed programs here show: the fixed program prints heap 1 and sorted 0 for the textbook case; the semantics program prints empty 1, single 1, heap 1, sorted 0, desc 1, minheap 1, heapgreater 0, until 4 value 10, untilheap end, and untilsorted 1 - the call returns true when the range satisfies the heap property under the comparator (vacuously for empty and single-element ranges), false at the first violation, the default comparator checks a max heap, std::greater checks a min heap, std::is_heap_until returns the first element that breaks the heap or the end over a full heap, and the documented cost is linear in the range length.
  • The classic std::is_heap dates to C++11: with <algorithm> included it compiles and runs as C++11, C++14, C++17, C++20, and C++23, each printing 1, and fails as C++98 with this same wording. The layered pieces have floors: the execution-policy overload starts at C++17 - naming the policy with only <algorithm> included fails with 'std::execution' has not been declared; with <execution> included alongside it, the policy call compiles and runs, returning the heap answer. Constant-expression use starts at C++20: the static-assert program here compiles as C++20 and fails as C++17.
  • The neighbors split in this library: std::find fails in a sole <vector> file with the suggestion did you mean 'std::ranges::find'?, std::count with did you mean 'popcount'?, and std::remove with did you mean 'move'?, while std::transform, std::sort, std::unique, and std::partition fail there with the plain error, and std::copy compiles outright in that file - all eight neighbors are declared by #include <algorithm> by rule. The fixed neighbor program prints is_heap 1, find 2 3, count 1, copy 1 6, transform 2 4 6 8 10 12, sort 1 2 3 4 5 6, remove 1 2 4 6 end 4, unique 1 2 3 end 3, and partition end 3.
  • The ranges form of this same name is a function object in namespace std::ranges, declared in <algorithm> by the standard, needing C++20, answering the same bool - compiled as C++17 the ranges program here fails with 'std::ranges' has not been declared, and compiled as C++20 it prints ranges 1, rangessorted 0, and rangesuntil end. In the probes here <ranges> alone does not rescue it in this library - it fails with a not-a-member error naming the ranges namespace for the ranges form, <array> alone fails for it the same way with the plain line alone on both transcripts, and <ranges> fails with the classic name's plain error for the classic name in the sweep.
  • 'is_heap' was not declared in this scope for an unqualified is_heap use is a different defect: qualify the name as std::is_heap - the include alone does not bring the name out of namespace std. For this name the unqualified call's fate depends on the iterators' types: over plain arrays it fails, as the first unqualified program above shows; over a vector's iterators and over a deque's iterators it is rescued through argument-dependent lookup, as the second and third show, because those iterators are std class types; over a std::array's iterators it fails again, because in this library those iterators are plain pointers; and with using namespace std; in the file it compiles outright, as the last unqualified program shows. Qualify the name either way.

The fixes, ranked

  • First, check the include list of the file that names std::is_heap. If <algorithm> is not there, add it - that is the fix for the usual cause of this error. It holds whether or not the file happened to compile before through one of the 6 transitive rescues and stopped compiling when its other includes changed.
  • Second, check the standard level: this name dates to C++11, so a build set to C++98 fails with this same wording even with the include in place - raise the standard to C++11 or later for the classic call. No standard upgrade fixes a missing include, and no include fixes a pre-C++11 build; the two causes need their own fixes.
  • Third, do not follow the one suggestion this name earns: the C++98 transcript's did you mean 'push_heap'? names a function that inserts into a heap, not the test for one - a suggestion is a spelling guess, never a fix, on this name's error or on a neighboring name's.
  • Fourth, do not reach for a container's header because the call tests a container, or for <iterator> because the call takes iterators. In the sweep probed here <vector>, <list>, <string>, and <iterator> all fail for this name - none of them is the declaring header by rule. The declaring header is <algorithm>, and a complete program names it alongside the container's own header.
  • Fifth, do not remove <algorithm> because a file compiles without it: in the probed set only 6 headers rescue the classic name, and those rescues are not guaranteed - a file that drops the include is one internal-include change away from the error in the first section. The same warning covers std::copy, which compiles in a sole <vector> file here by the same kind of accident.
  • Sixth, read a false answer as a heap-property answer, not as an error: the call answers false when any parent-child pair violates the property under the comparator in force - in the fixed program the ascending order answers false under the default max-heap check and true under std::greater - and use std::is_heap_until when the question is where the heap stops, not whether it holds.
  • Seventh, if the error names std::execution instead - 'std::execution' has not been declared - add <execution> alongside <algorithm> and keep the standard at C++17 or later: this name does have a policy overload, and that pair of changes is the whole fix for the policy form.
  • Eighth, match the standard to the one piece beyond the classic call that has a floor: constant-expression use needs C++20, and the ranges form needs C++20 - with its header still <algorithm> by the standard, not <ranges>.
  • Ninth, if the error says was not declared in this scope instead, fix the name's qualifier to std::is_heap as well - and do not rely on argument-dependent lookup to rescue the unqualified call, because a plain array and a std::array each remove that rescue in the probed set.

Sources

  • cppreference, std::is_heap - the function template is defined in <algorithm>; it checks whether a range represents a heap with respect to operator< ( std::less since C++20) or a given comparator, returns true or false, and its documented complexity is linear; the classic overloads are marked since C++11, the execution-policy overloads since C++17, and the classic overloads constexpr since C++20.
  • cppreference, std::is_heap_until - the companion function template, also defined in <algorithm> and since C++11, returning the past-the-end iterator of the largest prefix that represents a heap.
  • cppreference, <algorithm> header - the header that declares this name and the other algorithm names used as neighbors here.
  • cppreference, std::ranges::is_heap - the C++20 ranges form of this name, a function object in namespace std::ranges declared in <algorithm>, answering the same heap question for a range.

Keep Exploring