Cpp Std Includes Not Member Fix | Veldica
layout: landing
explore_theme: programming
analytics_page: cpp_std_includes_not_member_fix
analytics_page_view_event: page_view_cpp_std_includes_not_member_fix
page_title: "'std::includes' Is Not a Member of 'std' Fix"
page_description: "A program that uses std::includes fails with ''includes' is not a member of 'std'' when the #include
Written December 1, 2026
Tested with GCC 13.3.0
What this guide is
std::includes is a function template defined in the header <algorithm>. It reports whether the sorted target range [first2, last2) is a subsequence of the sorted source range [first1, last1) - whether every element of the target appears in the source, in order. With the plain overload the order is operator< (until C++20) / std::less{} (since C++20), and the comparator overload tests with respect to the comparison the program passes instead. It returns true when the target is a subsequence of the source and false otherwise - and an empty target range counts as included, so it returns true for an empty target (a defect report against C++98 already clarifies that return). Both ranges must be sorted with respect to the order in use; if either is not, the behavior is undefined. It makes at most 2·(N1+N2)-1 comparisons, where N1 and N2 are the lengths of the two ranges. Both plain overloads are constexpr since C++20, and std::includes does have execution-policy overloads, since C++17 - the fixed-programs section below runs one. Sorting a range in the first place is a separate step: std::sort has its own guide and is not re-taught here, and testing sortedness with std::is_sorted has its own guide too.
Because the template lives in one specific header, 'includes' 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>, it never prints note lines or help lines under the error, and it never adds a suggestion tail either - behind every failing sole header in the sweep the diagnostic is the plain error line and its caret block, nothing more. That uniformity is this name's own signature: its siblingstd::is_sortedgets a wrong-name suggestion,is_signed, behind 66 headers in its sweep, andstd::includesgets no suggestion behind any of them. The neighboring names probed here -std::set_union,std::set_intersection, andstd::search, all in the same header - fail just as plainly 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. The older siblings in this family - std::sort, std::is_sorted, std::binary_search, std::partial_sort, std::partition, and std::rotate - 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 asks whether a sorted array includes a sorted target and returns success if it does, but includes only <limits>:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
return std::includes(a, a + 6, b, b + 2) ? 0 : 1;
}
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:5:17: error: 'includes' is not a member of 'std'
5 | return std::includes(a, a + 6, b, b + 2) ? 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:
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
return std::includes(a, a + 6, b, b + 2) ? 0 : 1;
}
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:4:17: error: 'includes' is not a member of 'std'
4 | return std::includes(a, a + 6, b, b + 2) ? 0 : 1;
| ^~~~~~~~
The textbook version fails too - plainly, with no suggestion
The version most often written first - ask whether one sorted vector includes another and print the answer, with std::cout - gets the same error, without <algorithm>, and here too the error line carries no tail:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::cout << std::includes(v.begin(), v.end(), sub.begin(), sub.end()) << "\n";
return 0;
}
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:6:23: error: 'includes' is not a member of 'std'
6 | std::cout << std::includes(v.begin(), v.end(), sub.begin(), sub.end()) << "\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 - and nothing those headers pull in is close enough to includes for GCC to offer a suggestion, so there is no wrong name to be led by here, only the plain error. In the sweep probed here, the only headers that rescue std::includes are <chrono>, <execution>, <functional>, <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::includes includes <algorithm>, whether or not it happens to compile without it.
Neighboring headers: every failing header fails plainly, and five 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 asks whether a sorted array includes a sorted target and returns success if it does, 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 100 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><queue><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. No failing sole header prints a suggestion tail, note lines, or help lines - there is no variation in the whole failing set at all.
A sole <vector> file shows the plain shape in full:
#include <vector>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
return std::includes(a, a + 6, b, b + 2) ? 0 : 1;
}
$ g++ -std=c++20 v_vector.cpp -o v_vector_prog
v_vector.cpp: In function 'int main()':
v_vector.cpp:5:17: error: 'includes' is not a member of 'std'
5 | return std::includes(a, a + 6, b, b + 2) ? 0 : 1;
| ^~~~~~~~
And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><chrono><execution><functional><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, there is no suggestion class here at all: where std::is_sorted's sweep splits its failing headers between a plain class and a large is_signed suggestion class, this sweep's failing set is uniform - the one plain error behind all 100 headers, the textbook combination included. <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 = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::vector<int> notsub = {2, 7};
std::cout << std::includes(v.begin(), v.end(), sub.begin(), sub.end()) << " " << std::includes(v.begin(), v.end(), notsub.begin(), notsub.end()) << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
1 0
One include, <algorithm>, declares the template: the target {2, 4} is a subsequence of the sorted vector and reports 1, and the target {2, 7} - whose 7 appears nowhere in the source - reports 0, so the test distinguishes the two targets instead of answering 1 for everything.
The fixed programs: empty ranges, checked element by element
The answer leaves one thing to check independently: every element of the target is found in the source. This program runs that element-by-element search alongside std::includes, and reports the empty-range answers beside it:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::vector<int> e;
bool ok = std::includes(v.begin(), v.end(), sub.begin(), sub.end());
for (int x : sub) ok = ok && (std::find(v.begin(), v.end(), x) != v.end());
std::cout << ok << " " << std::includes(v.begin(), v.end(), e.begin(), e.end()) << " " << std::includes(e.begin(), e.end(), e.begin(), e.end()) << " " << std::includes(e.begin(), e.end(), sub.begin(), sub.end()) << "\n";
return 0;
}
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
1 1 1 0
Read in order: the element-by-element check confirms the inclusion, an empty target is included in the full range (1), an empty target is included in an empty source (1), and the nonempty target {2, 4} is not included in an empty source (0).
The comparator overload tests the order the program passes instead: with std::greater<int>() from <functional>, both ranges sorted descending, the descending target counts as included and a target holding a value the source lacks does not - the program prints 1 0:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {6, 5, 4, 3, 2, 1};
std::vector<int> sub = {5, 3};
std::vector<int> notsub = {5, 7};
std::cout << std::includes(v.begin(), v.end(), sub.begin(), sub.end(), std::greater<int>()) << " " << std::includes(v.begin(), v.end(), notsub.begin(), notsub.end(), std::greater<int>()) << "\n";
return 0;
}
$ g++ -std=c++20 j_comp.cpp -o j_comp_prog
$ ./j_comp_prog
1 0
There is also an execution-policy version to run. Passing std::execution::par as a first argument selects the policy overload that has existed since C++17, and the call compiles and runs, printing 1 for the included target:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::cout << std::includes(std::execution::par, v.begin(), v.end(), sub.begin(), sub.end()) << "\n";
return 0;
}
$ g++ -std=c++20 j_policy.cpp -o j_policy_prog
$ ./j_policy_prog
1
So an inclusion test can take a policy; the policy overloads are part of this name's own overload set, and <execution> is the header the policy argument itself comes from.
The neighboring names: same header, plain in the lean context
The names that std::includes is built alongside share its home header - the set operations and the subsequence search. In the lean context here - only <limits> included - they get no suggestion at all. std::set_union - the function template defined in <algorithm> that computes the union of two sorted ranges - gets its own error, again with no header note. It is shown here only as a neighbor, not re-taught:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
int out[8];
return std::set_union(a, a + 6, b, b + 2, out) == out + 6 ? 0 : 1;
}
$ g++ -std=c++20 b_set_union.cpp -o b_set_union_prog
b_set_union.cpp: In function 'int main()':
b_set_union.cpp:6:17: error: 'set_union' is not a member of 'std'
6 | return std::set_union(a, a + 6, b, b + 2, out) == out + 6 ? 0 : 1;
| ^~~~~~~~~
std::set_intersection - the function template defined in <algorithm> that computes the intersection of two sorted ranges - fails the same way:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
int out[2];
return std::set_intersection(a, a + 6, b, b + 2, out) == out + 2 ? 0 : 1;
}
$ g++ -std=c++20 b_set_intersection.cpp -o b_set_intersection_prog
b_set_intersection.cpp: In function 'int main()':
b_set_intersection.cpp:6:17: error: 'set_intersection' is not a member of 'std'
6 | return std::set_intersection(a, a + 6, b, b + 2, out) == out + 2 ? 0 : 1;
| ^~~~~~~~~~~~~~~~
And std::search - the function template defined in <algorithm> that searches for the first occurrence of a range of elements - fails the same way, again with no header note:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 3};
return std::search(a, a + 6, b, b + 2) == a + 1 ? 0 : 1;
}
$ g++ -std=c++20 b_search.cpp -o b_search_prog
b_search.cpp: In function 'int main()':
b_search.cpp:5:17: error: 'search' is not a member of 'std'
5 | return std::search(a, a + 6, b, b + 2) == a + 1 ? 0 : 1;
| ^~~~~~
One contrast is worth holding on to: in the lean programs here, includes, set_union, set_intersection, and search all get no note and no suggestion. Do not read that shape 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: the union of the two ranges holds 6 elements, their intersection holds 2, and the pattern {2, 3} is found in the source, printing 6 2 1:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::vector<int> pat = {2, 3};
std::vector<int> out;
std::set_union(v.begin(), v.end(), sub.begin(), sub.end(), std::back_inserter(out));
std::vector<int> inter;
std::set_intersection(v.begin(), v.end(), sub.begin(), sub.end(), std::back_inserter(inter));
bool found = std::search(v.begin(), v.end(), pat.begin(), pat.end()) == v.begin() + 1;
std::cout << out.size() << " " << inter.size() << " " << found << "\n";
return 0;
}
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
6 2 1
Since C++20 the same <algorithm> header also declares std::ranges::includes, the ranges form of the same test. It comes in two call shapes - an iterator pair, and a single range - and returns the answer directly: here both shapes report 1 for the included target and the single-range shape reports 0 for the target that is not included, printing 1 1 0. 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. Behind a sole <vector> the wording changes: the namespace exists there, but the name is missing from it, so the error is 'includes' is not a member of 'std::ranges':
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::vector<int> notsub = {2, 7};
std::cout << std::ranges::includes(v.begin(), v.end(), sub.begin(), sub.end()) << " " << std::ranges::includes(v, sub) << " " << std::ranges::includes(v, notsub) << "\n";
return 0;
}
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
1 1 0
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
return std::ranges::includes(a, a + 6, b, b + 2) ? 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:5:17: error: 'std::ranges' has not been declared
5 | return std::ranges::includes(a, a + 6, b, b + 2) ? 0 : 1;
| ^~~~~~
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
return std::ranges::includes(v.begin(), v.end(), sub.begin(), sub.end()) ? 0 : 1;
}
$ g++ -std=c++20 r3_ranges_vector.cpp -o r3_ranges_vector_prog
r3_ranges_vector.cpp: In function 'int main()':
r3_ranges_vector.cpp:5:25: error: 'includes' is not a member of 'std::ranges'
5 | return std::ranges::includes(v.begin(), v.end(), sub.begin(), sub.end()) ? 0 : 1;
| ^~~~~~~~
A different wording - and cases where the qualifier is not needed, and where it is
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 C arrays:
#include <algorithm>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {2, 4};
return includes(a, a + 6, b, b + 2) ? 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:5:12: error: 'includes' was not declared in this scope
5 | return includes(a, a + 6, b, b + 2) ? 0 : 1;
| ^~~~~~~~
g2_unqualified_ptr.cpp:5: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:439:1: note: 'std::includes'
439 | includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
| ^~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2621:34: note: 'std::ranges::includes'
2621 | inline constexpr __includes_fn includes{};
| ^~~~~~~~
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::includes itself, shown at its execution-policy declaration in the internal header the transcript names, and the second at std::ranges::includes. Qualify the name as std::includes; adding includes does not bring the name out of namespace std.
The same unqualified call with std::array iterators as its arguments fails the same way, for the same underlying reason on this library version - a std::array iterator is a raw pointer here, so it belongs to no namespace either:
#include <algorithm>
#include <array>
#include <iostream>
int main() {
std::array<int, 6> a = {1, 2, 3, 4, 5, 6};
std::array<int, 2> b = {2, 4};
std::cout << includes(a.begin(), a.end(), b.begin(), b.end()) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified_array.cpp -o g_unqualified_array_prog
g_unqualified_array.cpp: In function 'int main()':
g_unqualified_array.cpp:7:18: error: 'includes' was not declared in this scope
7 | std::cout << includes(a.begin(), a.end(), b.begin(), b.end()) << "\n";
| ^~~~~~~~
g_unqualified_array.cpp:7:18: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
from g_unqualified_array.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:439:1: note: 'std::includes'
439 | includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
| ^~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2621:34: note: 'std::ranges::includes'
2621 | inline constexpr __includes_fn includes{};
| ^~~~~~~~
The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 1, the answer for the included target:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> sub = {2, 4};
std::cout << includes(v.begin(), v.end(), sub.begin(), sub.end()) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
1
What happened: the vector iterators belong to namespace std, so argument-dependent lookup finds std::includes 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, and over this library version's std::array iterators, fails, as the transcripts above show. Write the qualifier either way.
The exact rule
std::includesis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here, every one of the other 100 headers in the library's header set - among them<iostream>,<vector>,<string>,<utility>,<limits>, and<version>- does not declare it, and neither does a file with no include at all.'includes' 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 - behind all 100 failing sole headers the error line is plain.- 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, and no failing header produces a suggestion tail - the uniform plain shape is the contrast with
std::is_sorted, whose sweep carries theis_signedsuggestion behind 66 headers. - In the sweep probed here, only five headers besides
<algorithm>rescuestd::includestransitively -<chrono>,<execution>,<functional>,<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::includesin. - Both ranges must be sorted with respect to the order in use, or the behavior is undefined; an empty target range is included in any source, including an empty one, and a nonempty target is not included in an empty source - the fixed programs here print
1 1 1 0for the confirmed inclusion and those three empty-range answers. std::includeshas the plain and comparator overloads, bothconstexprsince C++20, and execution-policy overloads since C++17: passingstd::execution::parwith<algorithm>and<execution>included compiles and runs.std::set_union,std::set_intersection, andstd::searchare 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::includesis declared by the same#include <algorithm>since C++20: with the include it reports the answer in both its iterator-pair and its single-range call shapes; in the lean context probed here it gets the error'std::ranges' has not been declaredwhen that include is missing, and behind a sole<vector>it gets'includes' is not a member of 'std::ranges'.'includes' was not declared in this scopefor an unqualifiedincludesuse over raw pointers - and overstd::arrayiterators on this library version - is a different defect: qualify the name asstd::includes- 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::includes. If<algorithm>is not there, add it - that is the fix in the common case, and it holds whether the file failed in a lean context, failed in a textbook file, 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 no suggestion behind any header and no note naming
<algorithm>behind any of them - 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 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<chrono>,<execution>,<functional>,<regex>, and<valarray>rescue it, and that rescue is not guaranteed. - Fifth, sort both ranges before the call, in the order the call will use.
std::includeson unsorted ranges is undefined behavior, not a0answer - the inclusion answer is only defined for sorted source and target ranges. - Sixth, an execution policy is allowed here: the policy overloads have existed since C++17, so a policy call that fails is failing for another reason - check that
<algorithm>and<execution>are both included before changing the call. - Seventh, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::includesas well - and do not rely on an unqualified call that happens to compile overstdvector iterators, because the same call over raw pointers and overstd::arrayiterators fails. - Eighth, if the failing name is a neighboring one, check its header before fixing:
set_union,set_intersection, andsearchtake the same added<algorithm>, whileswaptakes<utility>.
Which fix for which cause
#include <algorithm>missing,std::includesused in a file whose only include is one of the 100 headers listed as plain in the sweep section above, or that includes nothing: the message is'includes' is not a member of 'std', with no suggestion, no header note, and no help - add#include <algorithm>.std::includesused in a textbook file including<iostream>and<vector>: the message is the same plain error, with no suggestion tail - add#include <algorithm>.std::includesused with only<algorithm>,<chrono>,<execution>,<functional>,<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::includescalled with an execution policy as its first argument,<algorithm>and<execution>included: no error - the policy overloads exist since C++17 and the call runs.std::set_union,std::set_intersection, orstd::searchused without<algorithm>in the lean context: the message names that name, plainly, with no header note - add#include <algorithm>.std::ranges::includesused without<algorithm>in the lean context: the message is'std::ranges' has not been declared- add#include <algorithm>. Behind a sole<vector>the message is'includes' is not a member of 'std::ranges'- the same fix.includesused without thestd::qualifier,<algorithm>included, over raw pointers orstd::arrayiterators: the message is'includes' was not declared in this scope- qualify the name asstd::includes. 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 test, 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, and do not wait for a note naming the header. For this error, in the contexts probed here, GCC prints no suggestion behind any of the 100 failing headers and no note naming
<algorithm>behind any of them - 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::includesat all, and the five headers that do rescue it do so only transitively. - Sort both ranges, in the order the call uses, before calling: an inclusion answer over unsorted ranges is undefined, and the empty-target answer -
true- holds only under the sorted-ranges precondition. - One header per name the file uses:
std::vectorcomes from<vector>andstd::stringcomes from<string>, even in a program whose subject is the test - andstd::includescomes from<algorithm>in return. The comparator overload'sstd::greatercomes from<functional>, and the execution-policy overloads' policy comes from<execution>. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
1 0for the included and not-included targets, and1 1 1 0for the confirmed inclusion and the empty-range answers.
Related guides
- 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the full sorting function template in
<algorithm>, the operation that puts the ranges this guide's test reads into order: its own full header sweep, its error, and its fix are covered there. - 'std::is_sorted' Is Not a Member of 'std' Fix - the same missing-include shape for the sortedness test in
<algorithm>: its own full header sweep, its error, and its fix are covered there, and its sweep carries a large wrong-name suggestion class where this guide's sweep has none at all. - 'std::binary_search' Is Not a Member of 'std' Fix - the same missing-include shape for the sorted-range search function template in
<algorithm>: its own full header sweep, its error, and its fix are covered there.
Sources
- cppreference,
std::includes— forstd::includesbeing a function template defined in<algorithm>that checks whether the sorted target range is a subsequence of the sorted source range, with respect tooperator<(until C++20) /std::less{}(since C++20) for the plain overload and a comparator overload, bothconstexprsince C++20, execution-policy overloads since C++17, at most 2·(N1+N2)-1 comparisons for ranges of lengths N1 and N2, undefined behavior when either range is not sorted with respect to the order in use, returnstrueif the target range is a subsequence of the source range andfalseotherwise, and a defect report against C++98 clarifying that an empty target range returnstrue. - cppreference, Standard library header
<algorithm>— for<algorithm>being the header that declaresstd::includesand the neighboring algorithm names, including thestd::ranges::includesalgorithm function object since C++20. - cppreference,
std::ranges::includes— forstd::ranges::includesbeing an algorithm function object defined in<algorithm>since C++20,constexpr, constrained to input iterators and ranges, in an iterator-sentinel form and a range form, that checks whether a sorted target range is a subsequence of a sorted source range and returns that answer, at most 2·(N1+N2)-1 applications of the comparison and the projections. - cppreference,
std::set_union— forstd::set_unionbeing a function template defined in<algorithm>that computes the union of two sorted ranges. - cppreference,
std::set_intersection— forstd::set_intersectionbeing a function template defined in<algorithm>that computes the intersection of two sorted ranges. - cppreference,
std::search— forstd::searchbeing a function template defined in<algorithm>that searches for the first occurrence of a range of elements.