C++

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

std::partition lives in one header, <algorithm> - and on this library version almost no ordinary file rescues it by accident: in the sweep probed here only <functional>, <chrono>, <execution>, <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 splits by compile result only two ways - the plain error, with no suggestion tail, no note lines, and no help lines in any probed failing context, or one of those five transitive rescues - with no link-failure shape behind any probed header. 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 · 23 min read

By the end of this guide
  • The error: the include is missing, in a lean file
  • A neighboring header does not rescue it: only &lt;utility&gt;
  • The textbook version fails too - plainly, with no suggestion
  • Neighboring headers: which ones fail, which ones rescue it

Written December 1, 2026

Tested with GCC 13.3.0

What this guide is

std::partition is a function template defined in the header <algorithm>. It reorders the elements in a range [first, last) with respect to a unary predicate p: every element for which p returns true comes before every element for which it returns false, and it returns an iterator to the partition point - the first element for which p returns false, or last if there is none. The order of the elements inside each group is not preserved. The plain overload is constexpr since C++20; a second overload, since C++17, takes an execution policy as its first argument. The plain overload makes at most N swaps for a range of N elements - at most N/2 if the iterators are bidirectional - and exactly N applications of the predicate. To find the partition point of a range that is already partitioned, without moving anything, std::partition_point is the tool.

Because the template lives in one specific header, 'partition' 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 prints no note naming <algorithm>, no suggestion on the error line, no note lines, and no help lines, so the fix has to come from knowing the name's home, not from reading a diagnostic tail. The neighboring names probed here - std::lower_bound, std::upper_bound, std::equal_range, and std::binary_search, all in the same header - are silent the same way 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. In the sweep probed here the outcome splits by compile result only two ways - the plain compile error, or a transitive rescue - and the rescue side is small but wider than its closest sibling's: std::binary_search, probed in its own guide, is rescued by <functional> and <chrono> only, while here <execution> rescues std::partition as well, because the policy overload's declarations travel with that header, and <regex> and <valarray> rescue it too. There is also no near-name trap in this sweep: no probed header declares a similarly named std name that GCC could offer as a suggestion - std::partition_point, the closest relative, lives in <algorithm> itself, and no probed sole header declares it either, as its own mini-sweep below shows. The older siblings in this family - std::lower_bound, std::upper_bound, std::equal_range, std::binary_search, std::sort, and std::find - 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 partitions an array so the even values come first, with std::partition, and returns success if the partition point lands at index 3, but includes only <limits>:

C++
#include <limits>
int main() {
    int a[] = {5, 1, 4, 2, 3, 6};
    return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:17: error: 'partition' is not a member of 'std'
    4 |     return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~

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:

C++
int main() {
    int a[] = {5, 1, 4, 2, 3, 6};
    return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:17: error: 'partition' is not a member of 'std'
    3 |     return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~

A neighboring header does not rescue it: only <utility>

A reader coming from the std::swap error might reach for <utility> first. In the program probed here it changes nothing - the same plain error, at the same position:

C++
#include <utility>
int main() {
    int a[] = {5, 1, 4, 2, 3, 6};
    return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 u_utility.cpp -o u_utility_prog
u_utility.cpp: In function 'int main()':
u_utility.cpp:4:17: error: 'partition' is not a member of 'std'
    4 |     return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~

That is expected once the homes are separated: <utility> declares std::swap, and std::partition is not one of its names. The two errors share a shape and a sentence pattern, but each name takes its own header, and the fix below is <algorithm>, not the swap fix.

The textbook version fails too - plainly, with no suggestion

The version most often written first - partition a vector so the even values come first and print where the partition point lands, with std::cout - gets the same error, without <algorithm>:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    std::cout << std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:23: error: 'partition' is not a member of 'std'
    5 |     std::cout << std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin() << "\n";
      |                       ^~~~~~~~~

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. The error is also exactly as plain here as in the lean file: there is no did you mean tail on the error line, no note lines, and no help lines. Do not wait for a suggestion to point the way: the fix for the name the program means is the include below. In the sweep probed here, the only headers that rescue std::partition are <functional>, <chrono>, <execution>, <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::partition includes <algorithm>, whether or not it happens to compile without it.

Neighboring headers: which ones fail, which ones rescue it

In a sweep where each header below was compiled as the only header in a program that partitions an array so the even values come first and returns whether the partition point lands at index 3, 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 - and these headers fail with the plain is not a member of 'std' error, with no suggestion, no note, and no help:

  • <limits>
  • <cstring>
  • <cstdint>
  • <cstddef>
  • <initializer_list>
  • <version>
  • <climits>
  • <cctype>
  • <new>
  • <typeinfo>
  • <type_traits>
  • <compare>
  • <concepts>
  • <ratio>
  • <bit>
  • <optional>
  • <numeric>
  • <tuple>
  • <mutex>
  • <exception>
  • <utility>
  • <vector>
  • <string>
  • <iostream>
  • <memory>
  • <array>
  • <map>
  • <set>
  • <thread>
  • <stdexcept>
  • <iterator>
  • <system_error>
  • <semaphore>
  • <ranges>
  • <forward_list>

A file with no include at all fails the same way. And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:

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

Two contrasts with the neighboring sweeps are worth holding on to. First, the split here is two-way: in the sweep probed here, every failing sole header fails at compile time with the plain error - each one was also compiled to an object file on its own, and that step failed the same way - 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, there is no suggestion class in this sweep at all, and no near-name trap either: <semaphore>, which adds a did you mean 'binary_semaphore'? tail to the std::binary_search error, fails plainly here, and <ranges> - the header a reader might expect to carry the ranges form - fails plainly for the plain name too. The closest relative, std::partition_point, was swept on its own over eight sole headers: it fails plainly with <limits>, <vector>, <iostream>, and <ranges>, and is rescued by exactly the same set as std::partition - <algorithm>, <functional>, <chrono>, <execution>, <regex>, and <valarray> - so no probed header makes partition_point visible while partition stays missing, and GCC never gets the chance to offer one as a suggestion for the other. The rescue list, though, matches the short lists in this family: <algorithm> - the home header - is on this 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:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    std::cout << std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
3

One include, <algorithm>, declares the template. In the vector 5, 1, 4, 2, 3, 6 three values are even - 4, 2, and 6 - so the partition point lands at index 3 and the program prints 3.

The fixed programs: the point follows the predicate

With <algorithm> added, std::partition answers to whatever predicate the program passes. Partitioning three copies of the same vector by three different predicates - even, odd, and at least 4 - puts the point at index 3 each time, because each predicate holds for exactly three of the six values:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> a = {5, 1, 4, 2, 3, 6};
    std::vector<int> b = {5, 1, 4, 2, 3, 6};
    std::vector<int> c = {5, 1, 4, 2, 3, 6};
    std::cout << std::partition(a.begin(), a.end(), [](int x) { return x % 2 == 0; }) - a.begin() << " " << std::partition(b.begin(), b.end(), [](int x) { return x % 2 == 1; }) - b.begin() << " " << std::partition(c.begin(), c.end(), [](int x) { return x >= 4; }) - c.begin() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_cases.cpp -o i_cases_prog
$ ./i_cases_prog
3 3 3

The returned point is a real split, not just a count: after partitioning by even, every element before the point is even and every element from the point on is odd, which this program checks element by element and reports as 1, alongside the point itself at index 3:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    auto point = std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
    bool ok = true;
    for (auto it = v.begin(); it != point; ++it) ok = ok && (*it % 2 == 0);
    for (auto it = point; it != v.end(); ++it) ok = ok && (*it % 2 == 1);
    std::cout << ok << " " << (point - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
1 3

The execution-policy overload - the second overload, since C++17 - takes the policy as its first argument and needs <execution> for the policy itself. With std::execution::par the same partition puts the point at the same index, 3:

C++
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    std::cout << std::partition(std::execution::par, v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_policy.cpp -o j_policy_prog
$ ./j_policy_prog
3

The neighboring names: same header, same silence

The names that std::partition is built alongside share its home header and its silence. std::lower_bound - the function template defined in <algorithm> that returns an iterator to the first element not less than the value - gets its own error, again with no header note:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::lower_bound(a, a + 6, 5) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_lower.cpp -o b_lower_prog
b_lower.cpp: In function 'int main()':
b_lower.cpp:4:17: error: 'lower_bound' is not a member of 'std'
    4 |     return std::lower_bound(a, a + 6, 5) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~~~

std::upper_bound - the function template defined in <algorithm> that returns an iterator to the first element greater than the value - fails the same way:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::upper_bound(a, a + 6, 5) - a == 5 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 c_upper.cpp -o c_upper_prog
c_upper.cpp: In function 'int main()':
c_upper.cpp:4:17: error: 'upper_bound' is not a member of 'std'
    4 |     return std::upper_bound(a, a + 6, 5) - a == 5 ? 0 : 1;
      |                 ^~~~~~~~~~~

std::equal_range - the function template defined in <algorithm> that returns the pair of bounds bracketing the elements equal to the value - fails the same way:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(a, a + 6, 5);
    return r.second - r.first == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 d_equal.cpp -o d_equal_prog
d_equal.cpp: In function 'int main()':
d_equal.cpp:4:19: error: 'equal_range' is not a member of 'std'
    4 |     auto r = std::equal_range(a, a + 6, 5);
      |                   ^~~~~~~~~~~

std::binary_search - the function template defined in <algorithm> that reports whether an element equivalent to the value exists in a sorted range - fails the same way:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::binary_search(a, a + 6, 5) ? 0 : 1;
}
Terminal
$ g++ -std=c++20 e_binary.cpp -o e_binary_prog
e_binary.cpp: In function 'int main()':
e_binary.cpp:4:17: error: 'binary_search' is not a member of 'std'
    4 |     return std::binary_search(a, a + 6, 5) ? 0 : 1;
      |                 ^~~~~~~~~~~~~

And the closest relative of all, std::partition_point - the function template defined in <algorithm>, since C++11 and constexpr since C++20, that returns the partition point of a range that is already partitioned - fails the same way on an already-partitioned array, again with no header note:

C++
#include <limits>
int main() {
    int a[] = {2, 4, 6, 1, 3, 5};
    return std::partition_point(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 p_point_lean.cpp -o p_point_lean_prog
p_point_lean.cpp: In function 'int main()':
p_point_lean.cpp:4:17: error: 'partition_point' is not a member of 'std'
    4 |     return std::partition_point(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~~~~~~~

One contrast is worth holding on to: in the lean programs here, partition, lower_bound, upper_bound, equal_range, binary_search, and partition_point all get no note and no suggestion. Do not read the absence of a diagnostic tail as a puzzle to solve - in this probed set the tail is simply absent for this header's names in this context, and the fix comes from the names' home, <algorithm>.

The neighboring names, fixed

And the neighboring names work under the same one added header: std::lower_bound for 5 sits at index 3, std::upper_bound for 5 sits at index 5, the std::equal_range for 5 spans 2 elements, and std::binary_search reports 5 present as 1:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(v.begin(), v.end(), 5);
    std::cout << std::lower_bound(v.begin(), v.end(), 5) - v.begin() << " " << std::upper_bound(v.begin(), v.end(), 5) - v.begin() << " " << (r.second - r.first) << " " << std::binary_search(v.begin(), v.end(), 5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
3 5 2 1

std::partition_point agrees with the point std::partition returns: on the same vector, partitioned by even, both report index 3:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    auto point = std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
    std::cout << (point - v.begin()) << " " << (std::partition_point(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_ppoint_fixed.cpp -o k_ppoint_fixed_prog
$ ./k_ppoint_fixed_prog
3 3

Since C++20 the same <algorithm> header also declares std::ranges::partition, the ranges form of the same reordering. With <algorithm> included it takes the range itself instead of an iterator pair and returns the subrange from the partition point to the end of the range: here the tail starts at index 3 and holds 3 elements. 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:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    auto tail = std::ranges::partition(v, [](int x) { return x % 2 == 0; });
    std::cout << (tail.begin() - v.begin()) << " " << (tail.end() - tail.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
3 3
C++
#include <limits>
int main() {
    int a[] = {5, 1, 4, 2, 3, 6};
    auto tail = std::ranges::partition(a, [](int x) { return x % 2 == 0; });
    return tail.begin() - a == 3 ? 0 : 1;
}
Terminal
$ 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:22: error: 'std::ranges' has not been declared
    4 |     auto tail = std::ranges::partition(a, [](int x) { return x % 2 == 0; });
      |                      ^~~~~~

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:

C++
#include <algorithm>
int main() {
    int a[] = {5, 1, 4, 2, 3, 6};
    return partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
Terminal
$ 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:12: error: 'partition' was not declared in this scope
    4 |     return partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
      |            ^~~~~~~~~
g2_unqualified_ptr.cpp:4:12: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
                 from g2_unqualified_ptr.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:275:1: note:   'std::partition'
  275 | partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
      | ^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2330:35: note:   'std::ranges::partition'
 2330 |   inline constexpr __partition_fn partition{};
      |                                   ^~~~~~~~~

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 suggestions do name the right names - the first points at std::partition itself, at the execution-policy overload's declaration in the internal header the transcript names, and the second at std::ranges::partition. Qualify the name as std::partition; 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 3:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {5, 1, 4, 2, 3, 6};
    std::cout << partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
3

What happened: the iterators belong to namespace std, so argument-dependent lookup finds std::partition 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::partition is declared by #include <algorithm>, and by no other header by rule. In the sweep probed here, <limits>, <cstring>, <cstdint>, <cstddef>, <initializer_list>, <version>, <climits>, <cctype>, <new>, <typeinfo>, <type_traits>, <compare>, <concepts>, <ratio>, <bit>, <optional>, <numeric>, <tuple>, <mutex>, <exception>, <utility>, <vector>, <string>, <iostream>, <memory>, <array>, <map>, <set>, <thread>, <stdexcept>, <iterator>, <system_error>, <semaphore>, <ranges>, and <forward_list> do not declare it, and neither does a file with no include at all.
  • 'partition' is not a member of 'std' means the <algorithm> include is missing and nothing else in the file pulled the name in - and, in the contexts probed here, GCC prints no note naming <algorithm>, no suggestion on the error line, no note lines, and no help lines under it, in the textbook context as well as the lean ones.
  • In the sweep probed here, the split by compile result is two-way: a sole header either fails with that plain compile error or rescues the program. Each failing sole header also failed when compiled to an object file on its own, so the probed set contains no declared-but-not-defined link-failure shape for this name.
  • In the sweep probed here, only five headers besides <algorithm> rescue std::partition transitively - <functional>, <chrono>, <execution>, <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 pull std::partition in.
  • std::lower_bound, std::upper_bound, std::equal_range, std::binary_search, and std::partition_point are declared by the same #include <algorithm>: in the programs shown here, which include only <limits> beside the use, each gets its own is not a member of 'std' error when that include is missing, with no header note.
  • std::ranges::partition is declared by the same #include <algorithm> since C++20: with the include it partitions the range passed to it and returns the subrange from the partition point to the end, and in the lean context probed here it gets the error 'std::ranges' has not been declared when that include is missing.
  • 'partition' was not declared in this scope for an unqualified partition use over raw pointers is a different defect: qualify the name as std::partition - the include alone does not bring the name out of namespace std. The same unqualified use over std::vector iterators 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::partition. If <algorithm> is not there, add it - that is the fix in the common case, and it holds whether the file failed at compile time or happened to compile before through a transitive rescue.
  • Second, do not wait for a diagnostic tail to name the fix. In the contexts probed here this error carries no suggestion, no note, and no help - take the fix from the name the program means and its home header, <algorithm>.
  • Third, do not reach for <utility> because the error sentence looks like the std::swap error. In the program probed here, <utility> as the only include fails with the same plain 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>, <regex>, and <valarray> rescue it, and that rescue is not guaranteed.
  • Fifth, if the error says was not declared in this scope instead, fix the name's qualifier to std::partition as well - and do not rely on an unqualified call that happens to compile over std iterators, because the same call over raw pointers fails.
  • Sixth, if the failing name is a neighboring one, check its header before fixing: lower_bound, upper_bound, equal_range, binary_search, and partition_point take the same added <algorithm>, while swap takes <utility>.

Which fix for which cause

  • #include <algorithm> missing, std::partition used in a file whose only include is <limits>, <cstring>, <cstdint>, <cstddef>, <initializer_list>, <version>, <climits>, <cctype>, <new>, <typeinfo>, <type_traits>, <compare>, <concepts>, <ratio>, <bit>, <optional>, <numeric>, <tuple>, <mutex>, <exception>, <utility>, <vector>, <string>, <iostream>, <memory>, <array>, <map>, <set>, <thread>, <stdexcept>, <iterator>, <system_error>, <semaphore>, <ranges>, or <forward_list>, or that includes nothing: the message is 'partition' is not a member of 'std', with no suggestion, no header note, and no help - add #include <algorithm>.
  • std::partition used in a textbook file including <iostream> and <vector>: the message is the same plain error, with no suggestion - add #include <algorithm>.
  • std::partition used with only <algorithm>, <functional>, <chrono>, <execution>, <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::lower_bound, std::upper_bound, std::equal_range, std::binary_search, or std::partition_point used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • std::ranges::partition used without <algorithm> in the lean context: the message is 'std::ranges' has not been declared - add #include <algorithm>.
  • partition used without the std:: qualifier, <algorithm> included, over raw pointers: the message is 'partition' was not declared in this scope - qualify the name as std::partition. Over std::vector iterators 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 partition, 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 note or a suggestion naming the header. For this error, in the contexts probed here, GCC prints neither for partition - take the fix from the name's home header, <algorithm>, instead.
  • Do not import the std::swap fix into this error: in the probed set, <utility> fails here the same plain way as <limits> does. 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 rescue std::partition at all, and the five headers that do rescue it do so only transitively.
  • One header per name the file uses: std::vector comes from <vector> and std::string comes from <string>, even in a program whose subject is the partition - and std::partition comes from <algorithm> in return. The execution-policy overload additionally takes <execution> for the policy object itself.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 3 for the partition point of the even partition, and 1 3 for the split check and the point.

Sources

  • cppreference, std::partition — for std::partition being a function template defined in <algorithm> that reorders the elements in [first, last) so all elements for which the unary predicate p returns true come before all elements for which it returns false, returning the iterator to the partition point, with the plain overload constexpr since C++20, an execution-policy overload since C++17, at most N swaps (at most N/2 for bidirectional iterators) and exactly N applications of the predicate for the plain overload, and the iterators required to be forward iterators.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header that declares std::partition and the neighboring algorithm names, including the std::ranges::partition algorithm function object since C++20.
  • cppreference, std::partition_point — for std::partition_point being a function template defined in <algorithm>, since C++11 and constexpr since C++20, that returns the partition point of a range that is already partitioned with respect to the predicate, in O(log N) applications of the predicate, and for it being a more general form of std::lower_bound.
  • cppreference, std::ranges::partition — for std::ranges::partition being an algorithm function object defined in <algorithm> since C++20 that partitions a range or an iterator-sentinel pair and returns a subrange from the partition point to the end of the range.
  • cppreference, std::lower_bound — for std::lower_bound being a function template defined in <algorithm> that returns an iterator to the first element not less than the value.
  • cppreference, std::upper_bound — for std::upper_bound being a function template defined in <algorithm> that returns an iterator to the first element greater than the value.
  • cppreference, std::equal_range — for std::equal_range being a function template defined in <algorithm> that returns the pair of bounds bracketing the elements equal to the value.
  • cppreference, std::binary_search — for std::binary_search being a function template defined in <algorithm> that checks whether an element equivalent to the value exists in the partitioned range.

Keep Exploring