C++
'pop_heap' Is Not a Member of 'std' Fix
std::pop_heap lives in one header, <algorithm> - and on this library version almost no ordinary file rescues it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, only <functional>, <chrono>, <execution>, <queue>, <regex>, and <valarray> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. The error therefore surfaces in textbook files as well as lean ones, and in the sweep probed here it takes one shape - the plain error, with no suggestion tail behind any probed header - or a transitive rescue. This guide pins down both outcomes, which probed headers cause each one, and the one include that fixes the error by specification.
Written December 1, 2026 · Tested with GCC 13.3.0 · 22 min read
- The error: the include is missing, in a lean file
- The textbook version fails too - plainly
- Neighboring headers: which ones fail plainly, which ones rescue it
- The fix
Written December 1, 2026
Tested with GCC 13.3.0
What this guide is
std::pop_heap is a function template defined in the header <algorithm>. It removes the first element from the non-empty heap [first, last) by swapping the value at first and the value at last - 1, so the heap after the removal is [first, last - 1) and the removed element sits at position last - 1, where the program can read it or drop it with its container's own pop operation: with the plain overload the heap is ordered by operator< (since C++20, by std::less{}), so the element moved to the back is the largest one, and the comparator overload works on the heap built with respect to the comparison the program passes instead. It returns nothing. Both overloads are constexpr since C++20. Its iterators must be random-access iterators, and it makes at most 2log(N) comparisons, where N is the distance from first to last. There is no execution-policy overload of std::pop_heap - unlike the sorting algorithms, the heap algorithms were not given parallel overloads, and the fixed-programs section below shows what passing a policy does instead. Building the heap in the first place is a separate step: std::make_heap has its own guide and is not re-taught here, and adding an element to the heap with std::push_heap has its own guide too.
Because the template lives in one specific header, 'pop_heap' is not a member of 'std' has one common cause:
- 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, GCC never prints a note naming<algorithm>, and it never prints note lines, help lines, or a suggestion tail under the error - behind every failing sole header in the sweep the diagnostic is the plain error line and its caret block, nothing more. The neighboring names probed here -std::push_heap,std::sort_heap,std::is_heap, andstd::make_heap, all in the same header - get no suggestion either in the same lean context, as the neighboring-names section shows.
What makes this error worth separating from its relatives is the shape of the sweep behind it. The sweep probed here covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits two ways - the plain compile error or a transitive rescue, with no suggestion class at all. The rescue side is the heap-family pattern measured for this name in its own sweep: the five headers that rescue the sorting neighbors, plus <queue>, whose std::priority_queue is built on the heap algorithms. The older siblings in this family - std::make_heap, std::push_heap, std::partial_sort, std::nth_element, std::rotate, std::partition, and std::sort - have their own guides and are linked at the end, not re-taught here.
The error: the include is missing, in a lean file
This program pops the largest element off a heap held in an array with std::pop_heap and returns success if that element lands at the back, but includes only <limits>:
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
std::pop_heap(a, a + 6);
return a[5] == 6 ? 0 : 1;
}
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:10: error: 'pop_heap' is not a member of 'std'
4 | std::pop_heap(a, a + 6);
| ^~~~~~~~
That is the whole output: one error, no suggestion on the error line, no note lines, no help lines. The same program with no include at all fails the same way:
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
std::pop_heap(a, a + 6);
return a[5] == 6 ? 0 : 1;
}
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:10: error: 'pop_heap' is not a member of 'std'
3 | std::pop_heap(a, a + 6);
| ^~~~~~~~
The textbook version fails too - plainly
The version most often written first - pop the largest element off a heap over a vector and print it from the back of the range, with std::cout - gets the same error, without <algorithm>:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {6, 5, 4, 2, 3, 1};
std::pop_heap(v.begin(), v.end());
std::cout << v.back() << "\n";
return 0;
}
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:10: error: 'pop_heap' is not a member of 'std'
5 | std::pop_heap(v.begin(), v.end());
| ^~~~~~~~
What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one - and here the error is plain, with no suggestion tail at all. In the sweep probed here, the only headers that rescue std::pop_heap are <functional>, <chrono>, <execution>, <queue>, <regex>, and <valarray>, besides <algorithm> itself, and that rescue is a property of this library version, not a rule of the language. A program that uses std::pop_heap includes <algorithm>, whether or not it happens to compile without it.
Neighboring headers: which ones fail plainly, which ones rescue it
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 pops the largest element off a heap over an array and returns whether the back element holds it, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 99 headers fail with the plain is not a member of 'std' error, with no suggestion, no note, and no help:
<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 same plain way. No failing sole header adds a suggestion tail - the suggestion class for this name is empty.
A sole <vector> file shows the plain shape in full:
#include <vector>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
std::pop_heap(a, a + 6);
return a[5] == 6 ? 0 : 1;
}
$ g++ -std=c++20 v_vector.cpp -o v_vector_prog
v_vector.cpp: In function 'int main()':
v_vector.cpp:4:10: error: 'pop_heap' is not a member of 'std'
4 | std::pop_heap(a, a + 6);
| ^~~~~~~~
And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><chrono><execution><functional><queue><regex><valarray>
Two contrasts with the neighboring sweeps are worth holding on to. First, there is no link-failure shape in this sweep: every failing sole header fails at compile time with the error above, so the declared-but-not-defined link failure that std::swap produces behind five headers has no counterpart for this name in the probed set. Second, the rescue set carries one header the sorting neighbors do not: <queue>. Its class template std::priority_queue is implemented on top of the heap algorithms, and on this library version including it pulls std::pop_heap in on the side - still a transitive accident, not a declaration to rely on. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and every other rescue on that list is this library version's behavior, not a guarantee.
The fix
Add the header:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::make_heap(v.begin(), v.end());
std::pop_heap(v.begin(), v.end());
std::cout << v.back();
for (int x : v) std::cout << " " << x;
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
6 5 3 4 2 1 6
One include, <algorithm>, declares the template. The program first builds a heap over 5, 1, 4, 2, 3, 6 with std::make_heap, then pops it with std::pop_heap: the largest value, 6, moves to the back of the range, and the program prints that back element followed by the full contents, 6 5 3 4 2 1 6.
The fixed programs: the heap property of what remains, checked element by element
The pop leaves two things to check, not one: the removed element sits at the back, and the range in front of it is still a heap - every element at least as large as both of its heap children, the elements at positions 2i + 1 and 2i + 2, within the remaining range. This program checks both, the element-by-element pass alongside std::is_heap over [begin, end - 1), and reports 1, alongside the element at the back:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::make_heap(v.begin(), v.end());
std::pop_heap(v.begin(), v.end());
bool ok = (v.back() == 6) && std::is_heap(v.begin(), v.end() - 1);
for (std::size_t i = 0; i + 1 < v.size(); ++i) {
std::size_t l = 2 * i + 1, r = 2 * i + 2;
if (l + 1 < v.size()) ok = ok && (v[i] >= v[l]);
if (r + 1 < v.size()) ok = ok && (v[i] >= v[r]);
}
std::cout << ok << " " << v.back() << "\n";
return 0;
}
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
1 6
The comparator overload orders by the comparison the program passes instead: with std::greater<int>() from <functional>, the heap is a min heap - after popping it, the smallest value, 1, sits at the back, and std::is_heap over the remaining range under the same comparator confirms the property, so the program prints 1 1:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::make_heap(v.begin(), v.end(), std::greater<int>());
std::pop_heap(v.begin(), v.end(), std::greater<int>());
bool ok = std::is_heap(v.begin(), v.end() - 1, std::greater<int>());
std::cout << ok << " " << v.back() << "\n";
return 0;
}
$ g++ -std=c++20 j_comp.cpp -o j_comp_prog
$ ./j_comp_prog
1 1
There is no execution-policy version to run. Passing std::execution::par as a first argument does not select a parallel overload, because none exists - the call fails with no matching function for call to 'pop_heap', and the notes list the only two candidates there are, the plain overload and the comparator overload:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {6, 5, 4, 2, 3, 1};
std::pop_heap(std::execution::par, v.begin(), v.end());
std::cout << v.back() << "\n";
return 0;
}
$ g++ -std=c++20 j_policy.cpp -o j_policy_prog
j_policy.cpp: In function 'int main()':
j_policy.cpp:7:18: error: no matching function for call to 'pop_heap(const __pstl::execution::v1::parallel_policy&, std::vector<int>::iterator, std::vector<int>::iterator)'
7 | std::pop_heap(std::execution::par, v.begin(), v.end());
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/stl_algo.h:61,
from /usr/include/c++/13/algorithm:61,
from j_policy.cpp:1:
/usr/include/c++/13/bits/stl_heap.h:283:5: note: candidate: 'template<class _RAIter> constexpr void std::pop_heap(_RAIter, _RAIter)'
283 | pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
| ^~~~~~~~
/usr/include/c++/13/bits/stl_heap.h:283:5: note: template argument deduction/substitution failed:
j_policy.cpp:7:18: note: deduced conflicting types for parameter '_RAIter' ('__pstl::execution::v1::parallel_policy' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
7 | std::pop_heap(std::execution::par, v.begin(), v.end());
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_heap.h:317:5: note: candidate: 'template<class _RAIter, class _Compare> constexpr void std::pop_heap(_RAIter, _RAIter, _Compare)'
317 | pop_heap(_RandomAccessIterator __first,
| ^~~~~~~~
/usr/include/c++/13/bits/stl_heap.h:317:5: note: template argument deduction/substitution failed:
j_policy.cpp:7:18: note: deduced conflicting types for parameter '_RAIter' ('__pstl::execution::v1::parallel_policy' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
7 | std::pop_heap(std::execution::par, v.begin(), v.end());
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So an element is popped from a heap with the plain or comparator call, in the program's own thread; there is no policy argument to add, and <execution> is needed only for code that uses a policy with an algorithm that actually takes one.
The neighboring names: same header, plain in the lean context
The names that std::pop_heap is built alongside share its home header. In the lean context here - only <limits> included - they get no suggestion at all. std::push_heap - the function template defined in <algorithm> that inserts the element at the end of a range into the heap in front of it - gets its own error, again with no header note. Its own guide covers its error and its fix in full; it is shown here only as a neighbor:
#include <limits>
int main() {
int a[] = {6, 3, 5, 2, 1, 4, 7};
std::push_heap(a, a + 7);
return a[0] == 7 ? 0 : 1;
}
$ g++ -std=c++20 b_push.cpp -o b_push_prog
b_push.cpp: In function 'int main()':
b_push.cpp:4:10: error: 'push_heap' is not a member of 'std'
4 | std::push_heap(a, a + 7);
| ^~~~~~~~~
std::sort_heap - the function template defined in <algorithm> that turns a heap into a range sorted in ascending order - fails the same way:
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
std::sort_heap(a, a + 6);
return a[0] == 1 ? 0 : 1;
}
$ g++ -std=c++20 c_sortheap.cpp -o c_sortheap_prog
c_sortheap.cpp: In function 'int main()':
c_sortheap.cpp:4:10: error: 'sort_heap' is not a member of 'std'
4 | std::sort_heap(a, a + 6);
| ^~~~~~~~~
std::is_heap - the function template defined in <algorithm> that reports whether a range is a heap - fails the same way:
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
return std::is_heap(a, a + 6) ? 0 : 1;
}
$ g++ -std=c++20 d_isheap.cpp -o d_isheap_prog
d_isheap.cpp: In function 'int main()':
d_isheap.cpp:4:17: error: 'is_heap' is not a member of 'std'
4 | return std::is_heap(a, a + 6) ? 0 : 1;
| ^~~~~~~
And std::make_heap - the function template defined in <algorithm> that constructs a heap out of a range - fails the same way, again with no header note. Its own guide covers its error and its fix in full; it is shown here only as a neighbor:
#include <limits>
int main() {
int a[] = {5, 1, 4, 2, 3, 6};
std::make_heap(a, a + 6);
return a[0] == 6 ? 0 : 1;
}
$ g++ -std=c++20 e_makeheap.cpp -o e_makeheap_prog
e_makeheap.cpp: In function 'int main()':
e_makeheap.cpp:4:10: error: 'make_heap' is not a member of 'std'
4 | std::make_heap(a, a + 6);
| ^~~~~~~~~
One contrast is worth holding on to: in the lean programs here, pop_heap, push_heap, sort_heap, is_heap, and make_heap all get no note and no suggestion. Do not read the absence of a suggestion as a puzzle - in this probed set the fix comes from the names' home, <algorithm>, either way.
The neighboring names, fixed
And the neighboring names work under the same one added header: building a heap and confirming it with std::is_heap gives 1, pushing 7 puts 7 at the front, popping the heap moves that 7 to the back, and sorting the remaining heap leaves the range sorted ascending, 1 first and 6 last:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::make_heap(v.begin(), v.end());
bool h = std::is_heap(v.begin(), v.end());
v.push_back(7); std::push_heap(v.begin(), v.end());
int top = v[0];
std::pop_heap(v.begin(), v.end());
int popped = v.back(); v.pop_back();
std::sort_heap(v.begin(), v.end());
std::cout << h << " " << top << " " << popped << " " << v[0] << " " << v[5] << "\n";
return 0;
}
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
1 7 7 1 6
Since C++20 the same <algorithm> header also declares std::ranges::pop_heap, the ranges form of the same pop operation. It comes in two call shapes - an iterator pair, and a single range - and returns the past-the-end iterator of the range: here both shapes move 6 to the back of the range and return the end iterator, printing 6 1 6 1. In the lean context - only <limits> included - it fails with its own wording, 'std::ranges' has not been declared, because the namespace itself is not declared there:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {6, 5, 4, 2, 3, 1};
std::vector<int> w = {6, 5, 4, 2, 3, 1};
auto e1 = std::ranges::pop_heap(v.begin(), v.end());
auto e2 = std::ranges::pop_heap(w);
std::cout << v[5] << " " << (e1 == v.end()) << " " << w[5] << " " << (e2 == w.end()) << "\n";
return 0;
}
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
6 1 6 1
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
std::ranges::pop_heap(a, a + 6);
return a[5] == 6 ? 0 : 1;
}
$ g++ -std=c++20 r2_ranges_lean.cpp -o r2_ranges_lean_prog
r2_ranges_lean.cpp: In function 'int main()':
r2_ranges_lean.cpp:4:10: error: 'std::ranges' has not been declared
4 | std::ranges::pop_heap(a, a + 6);
| ^~~~~~
A different wording - and a case where the qualifier is not needed
Including <algorithm> is not the only half of the name - but for this function the unqualified form behaves two ways, and which one a program gets depends on its arguments. This program includes the header, drops the std:: qualifier, and passes raw pointers into a C array:
#include <algorithm>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
pop_heap(a, a + 6);
return a[5] == 6 ? 0 : 1;
}
$ g++ -std=c++20 g2_unqualified_ptr.cpp -o g2_unqualified_ptr_prog
g2_unqualified_ptr.cpp: In function 'int main()':
g2_unqualified_ptr.cpp:4:5: error: 'pop_heap' was not declared in this scope
4 | pop_heap(a, a + 6);
| ^~~~~~~~
g2_unqualified_ptr.cpp:4:5: note: suggested alternatives:
In file included from /usr/include/c++/13/bits/stl_algo.h:61,
from /usr/include/c++/13/algorithm:61,
from g2_unqualified_ptr.cpp:1:
/usr/include/c++/13/bits/stl_heap.h:317:5: note: 'std::pop_heap'
317 | pop_heap(_RandomAccessIterator __first,
| ^~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:1650:34: note: 'std::ranges::pop_heap'
1650 | inline constexpr __pop_heap_fn pop_heap{};
| ^~~~~~~~
That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not, and raw pointers belong to no namespace, so no lookup finds the name. Here the notes do name the right names - the first points at std::pop_heap itself, shown at its comparator declaration in the internal header the transcript names, and the second at std::ranges::pop_heap. Qualify the name as std::pop_heap; adding includes does not bring the name out of namespace std.
The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 6:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::make_heap(v.begin(), v.end());
pop_heap(v.begin(), v.end());
std::cout << v.back() << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
6
What happened: the iterators belong to namespace std, so argument-dependent lookup finds std::pop_heap from the arguments themselves, even without the qualifier. That is a property of the argument types, not a style to rely on: the same call over raw pointers fails, as the transcript above shows. Write the qualifier either way.
The exact rule
std::pop_heapis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here,, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , - ,
, 'pop_heap' is not a member of 'std'means the<algorithm>include is missing and nothing else in the file pulled the name in. In the contexts probed here, GCC prints no note naming<algorithm>, no note lines, no help lines, and no suggestion tail under it - the suggestion class in the probed set is empty.- In the sweep probed here, the split is two-way: a sole header either fails plainly or rescues the program. No probed sole header produces a declared-but-not-defined link-failure shape for this name.
- In the sweep probed here, only six headers besides
<algorithm>rescuestd::pop_heaptransitively -<functional>,<chrono>,<execution>,<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, those headers are not required to pullstd::pop_heapin. std::pop_heaphas only the plain and comparator overloads, bothconstexprsince C++20, and no execution-policy overload: passing a policy fails withno matching function for call to 'pop_heap', with the two existing overloads listed as the candidates.std::push_heap,std::sort_heap,std::is_heap, andstd::make_heapare declared by the same#include <algorithm>: in the programs shown here, which include only<limits>beside the use, each gets its ownis not a member of 'std'error when that include is missing, with no header note and no suggestion.std::ranges::pop_heapis declared by the same#include <algorithm>since C++20: with the include it pops the heap and returns the past-the-end iterator, in both its iterator-pair and its single-range call shapes, and in the lean context probed here it gets the error'std::ranges' has not been declaredwhen that include is missing.'pop_heap' was not declared in this scopefor an unqualifiedpop_heapuse over raw pointers is a different defect: qualify the name asstd::pop_heap- the include alone does not bring the name out of namespacestd. The same unqualified use overstd::vectoriterators compiles in the program probed here through argument-dependent lookup; qualify the name there too, so the call does not depend on its argument types.
The fixes, ranked
- First, check the include list of the file that names
std::pop_heap. If<algorithm>is not there, add it - that is the fix in the common case, and it holds whether the file failed plainly or happened to compile before through a transitive rescue. - Second, do not wait for a suggestion or a note naming the header. For this error, in the contexts probed here, GCC prints neither - take the fix from the name's home header,
<algorithm>, instead. - Third, do not reach for
<utility>because the error sentence looks like thestd::swaperror. In the sweep probed here,<utility>as the only include fails plainly with the same error - the two names live in different headers, and each takes its own. - Fourth, do not be reassured by
<iostream>,<vector>, or<string>being present - in the sweep here none of them rescues this name at all - and do not remove<algorithm>because a file compiles without it: in the probed set only<functional>,<chrono>,<execution>,<queue>,<regex>, and<valarray>rescue it, and that rescue is not guaranteed. - Fifth, do not add an execution policy to the call. There is no policy overload of
std::pop_heapto select - the call fails withno matching function for call to 'pop_heap'- so pop the element with the plain or comparator overload. - Sixth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::pop_heapas well - and do not rely on an unqualified call that happens to compile overstditerators, because the same call over raw pointers fails. - Seventh, if the failing name is a neighboring one, check its header before fixing:
push_heap,sort_heap,is_heap, andmake_heaptake the same added<algorithm>, whileswaptakes<utility>.
Which fix for which cause
#include <algorithm>missing,std::pop_heapused in a file whose only include is one of the 99 headers listed as plain in the sweep section above, or that includes nothing: the message is'pop_heap' is not a member of 'std', with no suggestion, no header note, and no help - add#include <algorithm>.std::pop_heapused in a textbook file including<iostream>and<vector>: the message is the same error, plainly, with no suggestion tail - add#include <algorithm>.std::pop_heapused with only<algorithm>,<functional>,<chrono>,<execution>,<queue>,<regex>, or<valarray>included: no error on this library version - add#include <algorithm>anyway when it is not the include already present, because the rescue is not guaranteed.std::pop_heapcalled with an execution policy as its first argument,<algorithm>included: the message isno matching function for call to 'pop_heap'- remove the policy; only the plain and comparator overloads exist.std::push_heap,std::sort_heap,std::is_heap, orstd::make_heapused without<algorithm>in the lean context: the message names that name, plainly, with no header note - add#include <algorithm>.std::ranges::pop_heapused without<algorithm>in the lean context: the message is'std::ranges' has not been declared- add#include <algorithm>.pop_heapused without thestd::qualifier,<algorithm>included, over raw pointers: the message is'pop_heap' was not declared in this scope- qualify the name asstd::pop_heap. Overstd::vectoriterators the same unqualified call compiles through argument-dependent lookup in the program probed here - qualify it anyway.
Checklist
- Check the include list of the file that names the pop, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Do not wait for a suggestion or a note naming the header. For this error, in the contexts probed here, GCC prints no suggestion tail and no note naming
<algorithm>- take the fix from the name's home header,<algorithm>, instead. - Do not import the
std::swapfix into this error: in the probed set,<utility>fails here too, plainly. Split neighboring names by home header first. - Do not assume the textbook includes rescue this name, and do not delete a working
<algorithm>line because a file compiles without it. In the sweep here<iostream>and<vector>do not rescuestd::pop_heapat all, and the six headers that do rescue it do so only transitively. - One header per name the file uses:
std::vectorcomes from<vector>andstd::stringcomes from<string>, even in a program whose subject is the heap - andstd::pop_heapcomes from<algorithm>in return. The comparator overload'sstd::greatercomes from<functional>, and there is no execution-policy overload to take<execution>for. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
6 5 3 4 2 1 6for the popped element and the full contents after the pop, and1 6for the heap-property check over the remaining range and the element it found at the back.
Related guides
- 'std::make_heap' Is Not a Member of 'std' Fix - the same missing-include shape for the heap-construction function template in
<algorithm>: its own full header sweep, its error, and its fix are covered there, and this guide links to it instead of re-teaching heap construction. - 'std::push_heap' Is Not a Member of 'std' Fix - the same missing-include shape for the heap-insertion function template in
<algorithm>, the mirror operation of the pop covered here: its own full header sweep, its error, and its fix are covered there. - 'std::partial_sort' Is Not a Member of 'std' Fix - the same missing-include shape for the partial sorting function template in
<algorithm>: its full header sweep splits three ways with a suggestion tail behind 2 failing headers, where this guide's sweep has no suggestion class at all. - 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the full sorting function template in
<algorithm>, an older sibling in this family whose own guide covers its error and its fix.
Sources
- cppreference,
std::pop_heap— forstd::pop_heapbeing a function template defined in<algorithm>that removes the first element from a non-empty heap by swapping the values atfirstandlast - 1so the heap after the removal is[first, last - 1), with the plain overload ordered byoperator<(until C++20) /std::less{}(since C++20) and a comparator overload, bothconstexprsince C++20, random-access iterators required, at most 2log(N) comparisons, returns none, and no execution-policy overload listed. - cppreference, Standard library header
<algorithm>— for<algorithm>being the header that declaresstd::pop_heapand the neighboring algorithm names, including thestd::ranges::pop_heapalgorithm function object since C++20. - cppreference,
std::ranges::pop_heap— forstd::ranges::pop_heapbeing an algorithm function object defined in<algorithm>since C++20,constexpr, in an iterator-sentinel form and a range form, that removes the first element from the heap and returns the past-the-end iterator of the range, at most 2log(N) applications of the comparison and twice as many projections. - cppreference,
std::make_heap— forstd::make_heapbeing a function template defined in<algorithm>that constructs a heap out of a range. - cppreference,
std::push_heap— forstd::push_heapbeing a function template defined in<algorithm>that inserts an element into a heap. - cppreference,
std::sort_heap— forstd::sort_heapbeing a function template defined in<algorithm>that turns a heap into a range of elements sorted in ascending order. - cppreference,
std::is_heap— forstd::is_heapbeing a function template defined in<algorithm>that checks whether a range is a heap.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.