C++
'std::find_end' Is Not a Member of 'std' Fix
std::find_end lives in one header, <algorithm> - and in the sweep probed here, covering all 106 standard headers in this library's header set, only 5 other headers pull it in on the side, so the textbook <vector> program fails outright. This name is one of the oldest in its family - it dates to C++98, so no standard setting rescues or causes this error - and its diagnostic is as plain as its siblings': not one of the 100 failing sole-header contexts decorates the error with a suggestion. This guide pins down the failing shapes, why the returned iterator names the last occurrence and not the first, why an empty target and a missing target both return the end, and the include that fixes the case by rule.
Written December 3, 2026 · Tested with GCC 13.3.0 · 27 min read
- The error: the include is missing
- The textbook version fails too - with no suggestion at all
- The suggestion in the sweep: there is none
- Neighboring headers: 100 fail plainly, none offers a suggestion, and 5 rescue it by accident
Written December 3, 2026
Tested with GCC 13.3.0
What this guide is
std::find_end is a function template defined in the header <algorithm>. It searches a range for the last occurrence of a second, target range and returns an iterator to the start of that occurrence: over 1, 2, 3, 1, 2, 3 with the target 1, 2, the answer is the occurrence that starts at position 3, not the one at position 0. When the target never occurs - or when the target is empty - it returns the end of the searched range instead, so one return value, the end iterator, covers both the no-match case and the empty-target case. Both ranges need only forward iterators. The equality overload compares elements with operator==; a second overload takes a binary predicate that decides when two elements count as equal. The classic call dates to C++98, has an execution-policy overload since C++17, and has been usable in constant expressions since C++20.
Because the function lives in <algorithm> - not in a container's header - 'find_end' is not a member of 'std' is the missing include, and naming that cause is the first step:
- The
#include <algorithm>line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, that second clause rarely saves anyone: in the sweep below, only 5 of the other 105 headers in the library's header set pull the name in on the side, so most files without<algorithm>do reach this error.
For this name the missing include is also the only cause of the error. std::find_end starts at C++98, so no standard setting produces this wording for the classic call: a file compiled as C++98 with <algorithm> included compiles and runs, as the versions section below shows. That sets this name apart from its younger siblings in this family, whose errors have a second, standard-based cause. The pieces layered on top still have floors of their own - the execution-policy overload needs C++17, and constant-expression use needs C++20 - and those floors belong to the added pieces, not to the classic call.
This name's diagnostic is also as plain as its siblings': in the sweep below, not one of the 100 failing sole-header contexts decorates the error with a did you mean tail. There is no wrong name to follow - but there is also no hint in the diagnostic about where the right name lives. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the rescue set has only 6 entries, because in this library the name is declared by a header that very little of the library includes.
The error: the include is missing
This program searches 1, 2, 3, 1, 2, 3 for the target 1, 2, but includes only <limits>:
#include <limits>
int main() {
int hay[6] = {1, 2, 3, 1, 2, 3};
int needle[2] = {1, 2};
auto it = std::find_end(hay, hay + 6, needle, needle + 2);
return 0;
}
-std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:5:20: error: 'find_end' is not a member of 'std'
5 | auto it = std::find_end(hay, hay + 6, needle, needle + 2);
| ^~~~~~~~
Read it in full: one plain error line - no suggestion tail rides on it, there are no note lines, and there are no help lines. Nothing in the diagnostic names <algorithm> or points anywhere at all. The same program with no include at all fails the same way:
-std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:4:20: error: 'find_end' is not a member of 'std'
4 | auto it = std::find_end(hay, hay + 6, needle, needle + 2);
| ^~~~~~~~
The textbook version fails too - with no suggestion at all
The version most often written first - run the search over vectors and print where the match starts - produces an error in this library, without <algorithm>, and the error is the same plain line:
#include <iostream>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto it = std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
std::cout << (it - hay.begin()) << "\n";
return 0;
}
-std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:6:20: error: 'find_end' is not a member of 'std'
6 | auto it = std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
| ^~~~~~~~
Nothing rescues the call here: <vector> does not pull the algorithm in - in the sweep below it fails for this name, with this same plain error. And there is no suggestion to misread: this name's error offers nothing, so the only move it leaves is the right one. A program that uses std::find_end includes <algorithm>, whether or not it happens to compile without it. A sole <algorithm> file makes the point in miniature - the call compiles and runs with nothing else in sight:
-std=c++20 i_algorithm.cpp -o i_algorithm_prog
$ ./i_algorithm_prog
The suggestion in the sweep: there is none
The textbook file is typical, not unlucky. In the sweep below, all 100 failing sole-header contexts fail with the plain error line alone - not one of them carries a did you mean tail. That is a property of this name in this library: no header in the set declares a name close enough to find_end, in a context where the algorithm itself is missing, for the compiler to offer a guess.
So for this name the diagnostic gives the reader exactly one piece of information - the name is not a member of std in this file - and the fix has to come from knowing the declaring header, not from reading the error. The move is the same either way: name the declaring header.
Neighboring headers: 100 fail plainly, none offers a suggestion, and 5 rescue it by accident
In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that searches 1, 2, 3, 1, 2, 3 for the last occurrence of 1, 2 and requires the match at position 3 back, the outcome splits two ways - the plain failure, or a rescue. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 100 headers all fail with the plain is not a member of 'std' error line - no suggestion tail on that line, no note lines, and no help lines:
<any><array><atomic><barrier><bit><bitset><cassert><ccomplex><cctype><cerrno><cfenv><cfloat><charconv><cinttypes><ciso646><climits><clocale><cmath><codecvt><compare><complex><concepts><condition_variable><coroutine><csetjmp><csignal><cstdalign><cstdarg><cstdbool><cstddef><cstdint><cstdio><cstdlib><cstring><ctgmath><ctime><cuchar><cwchar><cwctype><deque><exception><expected><filesystem><format><forward_list><fstream><future><initializer_list><iomanip><ios><iosfwd><iostream><istream><iterator><latch><limits><list><locale><map><memory><memory_resource><mutex><new><numbers><numeric><optional><ostream><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. Two entries deserve a pause. <limits> fails plainly: the header of the numeric limits declares nothing close enough to this name to trigger a guess. <ranges> fails plainly for the classic name: the C++20 ranges library has its own find-end name, and it does not bring this one in - that name gets its own section below. And <vector> - the header of the container this call most often reads - fails plainly, as the textbook section above shows.
No failing header in any shape produced a suggestion, a help line, or a different error.
And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><chrono><execution><functional><regex><valarray>
The declaring header in this library sits underneath very little - a time header, a policy header, a function-object header, the regular-expression header, and the numeric-array header - so the rescue set runs to only 5 transitive entries. That is also why the failing set is nearly the whole library here: with 100 of the other 105 headers failing, the missing include shows itself in almost any file that does not name <algorithm>. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and the other 5 rescues are this library version's behavior, not a guarantee.
The fix
Add the header:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto it = std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
std::cout << "result " << (it - hay.begin()) << " " << *it << "\n";
return 0;
}
-std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
result 3 1
One include, <algorithm>, declares the function - and the textbook program prints result 3 1: the last occurrence of 1, 2 in 1, 2, 3, 1, 2, 3 starts at position 3, and the element there is 1. The name is now declared by a header the file names itself, instead of by an internal include of one of the 5 rescuing headers that a different library version is free to rearrange. For a file that does fail - the <limits> shape above, or any other - the same one include is the whole fix, at every standard level: this name has no floor case, as the versions section below shows.
What the call does: it returns the last occurrence, and the end when there is none
The call's whole result is the returned iterator, and its defining choice is which occurrence it names: where std::search stops at the first occurrence of the target, this call reports the last one, and occurrences may overlap - a later occurrence that starts inside an earlier one still counts. The end of the searched range does double duty as the failure answer: a target that never occurs returns it, and so does an empty target. This program walks the shapes in order:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto it0 = std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
std::cout << "last " << (it0 - hay.begin()) << " " << *it0 << "\n";
auto itf = std::search(hay.begin(), hay.end(), needle.begin(), needle.end());
std::cout << "first " << (itf - hay.begin()) << "\n";
std::vector<int> empty;
auto it1 = std::find_end(hay.begin(), hay.end(), empty.begin(), empty.end());
std::cout << "empty " << (it1 == hay.end() ? "end" : "mid") << " " << (it1 - hay.begin()) << "\n";
std::vector<int> miss = {4, 5};
auto it2 = std::find_end(hay.begin(), hay.end(), miss.begin(), miss.end());
std::cout << "miss " << (it2 == hay.end() ? "end" : "mid") << " " << (it2 - hay.begin()) << "\n";
std::vector<int> ones = {1, 1, 1};
std::vector<int> pair = {1, 1};
auto it3 = std::find_end(ones.begin(), ones.end(), pair.begin(), pair.end());
std::cout << "overlap " << (it3 - ones.begin()) << "\n";
std::vector<int> phay = {1, -2, 3, -2};
std::vector<int> pneedle = {2};
int calls = 0;
auto abseq = [&calls](int a, int b) { ++calls; return std::abs(a) == std::abs(b); };
auto it4 = std::find_end(phay.begin(), phay.end(), pneedle.begin(), pneedle.end(), abseq);
std::cout << "match " << (it4 - phay.begin()) << " " << *it4 << " calls " << calls << "\n";
return 0;
}
-std=c++20 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
last 3 1
first 0
empty end 6
miss end 6
overlap 1
match 3 -2 calls 1
Read in order: the last line reports position 3 and the value 1 - the target 1, 2 occurs at positions 0 and 3 in 1, 2, 3, 1, 2, 3, and this call names the later start. The first line, from std::search over the same ranges, reports position 0 - the two calls differ only in which occurrence they keep. The empty line reports end at position 6: an empty target returns the end of the searched range, not its start, so an empty search and a failed search cannot be told apart from the return value alone. The miss line reports the same end 6 for the target 4, 5, which never occurs. The overlap line reports position 1: over 1, 1, 1 the target 1, 1 occurs at positions 0 and 1, sharing an element, and the last start is 1. The match line reports position 3, the value -2, and calls 1: the predicate overload treats elements as equal when their absolute values match, the target 2 last matches the -2 at position 3, and in this library that search applied the predicate once.
The cost rule follows from the documented bound: with a searched range of length N1 and a target of length N2, the call makes at most N2 times (N1 minus N2 plus 1) comparisons - every possible start position, checked element by element in the worst case.
Versions: no floor for the classic call - it dates to C++98
This call has no floor inside the probed set. std::find_end dates to C++98 - the cppreference page carries no since-C++11 marker on the classic overloads, and its defect reports are applied to C++98, which only makes sense for a name that already existed there. The fixed programs in this guide are compiled as C++20, but the name is far older than that: with <algorithm> included, the same search compiled as C++98 compiles and runs, printing 3, and as C++11, C++14, and C++17 the same way:
#include <algorithm>
#include <iostream>
int main() {
int hay[6] = {1, 2, 3, 1, 2, 3};
int needle[2] = {1, 2};
int* it = std::find_end(hay, hay + 6, needle, needle + 2);
std::cout << (it - hay) << "\n";
return 0;
}
-std=c++98 c_version98.cpp -o c_version98_prog
$ ./c_version98_prog
3
So this name's error has one cause, not two: a missing <algorithm>. A file that includes <algorithm> and still sees this error does not have a standard problem; the include is not reaching the file that names the call, or the name in the file is not this name. No standard upgrade fixes a missing include, and no include change is needed for an old standard - the two halves of the family's usual advice separate cleanly for this name.
The pieces layered on top of the classic call carry their own floors, and naming one splits in two when a reader tries it. This name does have an execution-policy overload, since C++17 - and naming the policy with only <algorithm> included fails on the policy's name, not the algorithm's:
#include <algorithm>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto it = std::find_end(std::execution::seq, hay.begin(), hay.end(), needle.begin(), needle.end());
return (it - hay.begin() == 3) ? 0 : 1;
}
-std=c++20 p_policy_algonly.cpp -o p_policy_algonly_prog
p_policy_algonly.cpp: In function 'int main()':
p_policy_algonly.cpp:6:34: error: 'std::execution' has not been declared
6 | auto it = std::find_end(std::execution::seq, hay.begin(), hay.end(), needle.begin(), needle.end());
| ^~~~~~~~~
That wording - has not been declared, naming std::execution - is the missing-header shape, and here adding the header is the whole fix: add <execution> alongside <algorithm>, and the same call compiles and runs, because the policy overload of std::find_end exists:
-std=c++20 p_policy_both.cpp -o p_policy_both_prog
$ ./p_policy_both_prog
The policy form belongs to this name, and it carries the C++17 floor. Compiled as C++14, the same two-header program fails on the policy's name again - at that standard the policy names are not there to be declared:
-std=c++14 p_policy_cpp14.cpp -o p_policy_cpp14_prog
p_policy_cpp14.cpp: In function 'int main()':
p_policy_cpp14.cpp:7:34: error: 'std::execution' has not been declared
7 | auto it = std::find_end(std::execution::seq, hay.begin(), hay.end(), needle.begin(), needle.end());
| ^~~~~~~~~
And since C++20 the classic call is also usable in constant expressions - this program's check happens at compile time, and the assertion on the result is part of the build:
#include <algorithm>
#include <array>
constexpr long check() {
std::array<int, 6> hay{1, 2, 3, 1, 2, 3};
std::array<int, 2> needle{1, 2};
return std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end()) - hay.begin();
}
static_assert(check() == 3);
int main() { return 0; }
-std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog
Compiled as C++17, the same program fails - the call is not a constant expression there, and the static assertion cannot hold:
-std=c++17 c_constexpr17.cpp -o c_constexpr17_prog
c_constexpr17.cpp: In function 'constexpr long int check()':
c_constexpr17.cpp:6:25: warning: call to non-'constexpr' function '_FIter1 std::find_end(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int*; _FIter2 = int*]' [-Winvalid-constexpr]
6 | return std::find_end(hay.begin(), hay.end(), needle.begin(), needle.end()) - hay.begin();
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:373:5: note: '_FIter1 std::find_end(_FIter1, _FIter1, _FIter2, _FIter2) [with _FIter1 = int*; _FIter2 = int*]' declared here
373 | find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
| ^~~~~~~
c_constexpr17.cpp: At global scope:
c_constexpr17.cpp:8:23: error: non-constant condition for static assertion
8 | static_assert(check() == 3);
| ~~~~~~~~^~~
c_constexpr17.cpp:8:20: error: 'constexpr long int check()' called in a constant expression
8 | static_assert(check() == 3);
| ~~~~~^~
c_constexpr17.cpp:3:16: note: 'constexpr long int check()' declared here
3 | constexpr long check() {
| ^~~~~
So C++20 is the floor for that layered piece and C++17 is the floor for the policy form - and no standard at any level rescues a missing include, while the classic call needs nothing beyond <algorithm> at any standard from C++98 up.
The neighboring names: all six fail, four with suggestions that point into the ranges library
The names a reader most often reaches for alongside this one mostly live in <algorithm> too, and in a file whose only include is <vector> this family fails six ways - no member of it compiles at all. std::find, which returns an iterator to the first element equal to a value, fails with a suggestion that points into the ranges library:
-std=c++20 b_find_vector.cpp -o b_find_vector_prog
b_find_vector.cpp: In function 'int main()':
b_find_vector.cpp:5:20: error: 'find' is not a member of 'std'; did you mean 'std::ranges::find'?
5 | auto it = std::find(v.begin(), v.end(), 3);
| ^~~~
In file included from /usr/include/c++/13/tuple:44,
from /usr/include/c++/13/bits/uses_allocator_args.h:38,
from /usr/include/c++/13/bits/memory_resource.h:41,
from /usr/include/c++/13/vector:80,
from b_find_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:499:30: note: 'std::ranges::find' declared here
499 | inline constexpr __find_fn find{};
| ^~~~
std::find_if, which returns an iterator to the first element the predicate passes, fails with the same kind of suggestion:
-std=c++20 b_findif_vector.cpp -o b_findif_vector_prog
b_findif_vector.cpp: In function 'int main()':
b_findif_vector.cpp:5:20: error: 'find_if' is not a member of 'std'; did you mean 'std::ranges::find_if'?
5 | auto it = std::find_if(v.begin(), v.end(), [](int x) { return x > 2; });
| ^~~~~~~
In file included from /usr/include/c++/13/tuple:44,
from /usr/include/c++/13/bits/uses_allocator_args.h:38,
from /usr/include/c++/13/bits/memory_resource.h:41,
from /usr/include/c++/13/vector:80,
from b_findif_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:527:33: note: 'std::ranges::find_if' declared here
527 | inline constexpr __find_if_fn find_if{};
| ^~~~~~~
std::search - this call's first-occurrence counterpart - fails with its own ranges suggestion:
-std=c++20 b_search_vector.cpp -o b_search_vector_prog
b_search_vector.cpp: In function 'int main()':
b_search_vector.cpp:5:20: error: 'search' is not a member of 'std'; did you mean 'std::ranges::search'?
5 | auto it = std::search(v.begin(), v.end(), needle.begin(), needle.end());
| ^~~~~~
In file included from /usr/include/c++/13/tuple:44,
from /usr/include/c++/13/bits/uses_allocator_args.h:38,
from /usr/include/c++/13/bits/memory_resource.h:41,
from /usr/include/c++/13/vector:80,
from b_search_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:684:32: note: 'std::ranges::search' declared here
684 | inline constexpr __search_fn search{};
| ^~~~~~
std::search_n, which searches for a run of consecutive copies of a value, fails with the plain error:
-std=c++20 b_searchn_vector.cpp -o b_searchn_vector_prog
b_searchn_vector.cpp: In function 'int main()':
b_searchn_vector.cpp:5:20: error: 'search_n' is not a member of 'std'
5 | auto it = std::search_n(v.begin(), v.end(), 2, 1);
| ^~~~~~~~
std::adjacent_find, which finds the first pair of adjacent equal elements, fails with a ranges suggestion:
-std=c++20 b_adjacentfind_vector.cpp -o b_adjacentfind_vector_prog
b_adjacentfind_vector.cpp: In function 'int main()':
b_adjacentfind_vector.cpp:5:20: error: 'adjacent_find' is not a member of 'std'; did you mean 'std::ranges::adjacent_find'?
5 | auto it = std::adjacent_find(v.begin(), v.end());
| ^~~~~~~~~~~~~
In file included from /usr/include/c++/13/tuple:44,
from /usr/include/c++/13/bits/uses_allocator_args.h:38,
from /usr/include/c++/13/bits/memory_resource.h:41,
from /usr/include/c++/13/vector:80,
from b_adjacentfind_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:776:39: note: 'std::ranges::adjacent_find' declared here
776 | inline constexpr __adjacent_find_fn adjacent_find{};
| ^~~~~~~~~~~~~
While std::find_first_of, which finds the first element equal to any element of a second range, fails with the plain error too:
-std=c++20 b_findfirstof_vector.cpp -o b_findfirstof_vector_prog
b_findfirstof_vector.cpp: In function 'int main()':
b_findfirstof_vector.cpp:5:20: error: 'find_first_of' is not a member of 'std'
5 | auto it = std::find_first_of(v.begin(), v.end(), needle.begin(), needle.end());
| ^~~~~~~~~~~~~
No suggestion in this set is a member of this guide's family: each one names the ranges form of the same neighbor - a different name in a different namespace, with its own header rule and, for the subsequence searches, a different return shape. And here nothing compiles - all six names wait for the same header. The failing neighbors are shown here only as neighbors, not re-taught.
The neighboring names, fixed
Together the seven names take one header between them - <algorithm> for all of them, with <vector> covering only the containers they work on. The fixed neighbor program reports all seven operations over the range 1, 2, 3, 1, 2, 3:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto fe = std::find_end(v.begin(), v.end(), needle.begin(), needle.end());
std::cout << "find_end " << (fe - v.begin()) << " " << *fe << "\n";
auto f = std::find(v.begin(), v.end(), 3);
std::cout << "find " << (f - v.begin()) << " " << *f << "\n";
auto fi = std::find_if(v.begin(), v.end(), [](int x) { return x > 2; });
std::cout << "find_if " << (fi - v.begin()) << " " << *fi << "\n";
auto se = std::search(v.begin(), v.end(), needle.begin(), needle.end());
std::cout << "search " << (se - v.begin()) << " " << *se << "\n";
auto sn = std::search_n(v.begin(), v.end(), 1, 3);
std::cout << "search_n " << (sn == v.end() ? -1 : (int)(sn - v.begin())) << "\n";
auto af = std::adjacent_find(v.begin(), v.end());
std::cout << "adjacent_find " << (af == v.end() ? -1 : (int)(af - v.begin())) << "\n";
auto ffo = std::find_first_of(v.begin(), v.end(), needle.begin(), needle.end());
std::cout << "find_first_of " << (ffo - v.begin()) << " " << *ffo << "\n";
return 0;
}
-std=c++20 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
find_end 3 1
find 2 3
find_if 2 3
search 0 1
search_n 2
adjacent_find -1
find_first_of 0 1
Read in order: find_end reports position 3 and the value 1 - the last start of the target 1, 2. find reports position 2 and the value 3 - the first element equal to 3. find_if reports the same position and value - the first element greater than 2 is that same 3. search reports position 0 and the value 1 - the first start of the same target whose last start find_end reported. search_n reports position 2 - a run of one 3 starts there. adjacent_find reports -1 - the program's stand-in for the end iterator, because no two adjacent elements are equal in this range. And find_first_of reports position 0 and the value 1 - the first element that appears in the target range at all.
A ranges form since C++20, in the same header
C++20 added a ranges form of this name, and the standard declares it in the same header as the classic name. std::ranges::find_end is a function object in the ranges namespace, declared in <algorithm>, that accepts two whole ranges and returns a subrange of the searched range - the found occurrence itself, not a single iterator. Compiled as C++20 it answers for the same vectors:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto r = std::ranges::find_end(hay, needle);
std::cout << "ranges " << (r.begin() - hay.begin()) << " " << *r.begin() << " " << (r.end() - hay.begin()) << "\n";
return 0;
}
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
ranges 3 1 5
The ranges line reports a subrange starting at position 3 with the value 1 and ending at position 5 - the start agrees with the classic form, and the return carries the occurrence's extent as well. Two boundaries and one library behavior keep the forms straight. The ranges form needs C++20: compiled as C++17, that same program fails on the namespace itself, with 'std::ranges' has not been declared:
-std=c++17 r_ranges_cpp17.cpp -o r_ranges_cpp17_prog
r_ranges_cpp17.cpp: In function 'int main()':
r_ranges_cpp17.cpp:7:19: error: 'std::ranges' has not been declared
7 | auto r = std::ranges::find_end(hay, needle);
| ^~~~~~~~
And in this library the ranges header does not rescue the ranges form - a file whose only include is <ranges> (with <vector> for the containers) fails for it with a not-a-member error naming the ranges namespace, and a file whose only include is <array> fails for it the same way, the two transcripts identical in shape:
-std=c++20 r_ranges_rangesonly.cpp -o r_ranges_rangesonly_prog
r_ranges_rangesonly.cpp: In function 'int main()':
r_ranges_rangesonly.cpp:6:27: error: 'find_end' is not a member of 'std::ranges'
6 | auto r = std::ranges::find_end(hay, needle);
| ^~~~~~~~
-std=c++20 r_ranges_arrayonly.cpp -o r_ranges_arrayonly_prog
r_ranges_arrayonly.cpp: In function 'int main()':
r_ranges_arrayonly.cpp:5:27: error: 'find_end' is not a member of 'std::ranges'
5 | auto r = std::ranges::find_end(hay, needle);
| ^~~~~~~~
That is this library version's behavior, not the rule: the header the standard names for both forms is <algorithm>, so a complete program names it. The classic name, meanwhile, is not pulled in by the ranges header either: in the sweep probed here, a file whose only include is <ranges> fails for std::find_end with the plain error, as the sweep section above lists.
A different wording - and an argument-dependent rescue that depends on the iterators' types
Including <algorithm> is not the only half of the name. Over plain arrays, the unqualified call fails:
#include <algorithm>
int main() {
int hay[6] = {1, 2, 3, 1, 2, 3};
int needle[2] = {1, 2};
auto it = find_end(hay, hay + 6, needle, needle + 2);
return 0;
}
-std=c++20 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:15: error: 'find_end' was not declared in this scope
5 | auto it = find_end(hay, hay + 6, needle, needle + 2);
| ^~~~~~~~
g_unqualified.cpp:5:15: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:71:1: note: 'std::find_end'
71 | find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
| ^~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:510:34: note: 'std::ranges::find_end'
510 | inline constexpr __find_end_fn find_end{};
| ^~~~~~~~
That wording - was not declared in this scope, with notes pointing at the declarations of both std::find_end and the ranges form - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::find_end; adding includes does not bring the name out of namespace std. Swap the arrays for vectors, and the same unqualified call compiles and runs:
#include <algorithm>
#include <vector>
int main() {
std::vector<int> hay = {1, 2, 3, 1, 2, 3};
std::vector<int> needle = {1, 2};
auto it = find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
return (it - hay.begin() == 3) ? 0 : 1;
}
-std=c++20 g_unqualified_vec.cpp -o g_unqualified_vec_prog
$ ./g_unqualified_vec_prog
That compile is argument-dependent lookup at work, not a rule to rely on: the vectors' iterators are std types, so their associated namespace is std, and lookup finds std::find_end through them. A list's iterators rescue it the same way - the same unqualified call over lists compiles and runs:
-std=c++20 g_unqualified_list.cpp -o g_unqualified_list_prog
$ ./g_unqualified_list_prog
But the container being a std type is not enough by itself - over a std::array, the same unqualified call fails with the same wording, because in this library a std::array's iterators are plain pointers, and a pointer has no associated namespace:
#include <algorithm>
#include <array>
int main() {
std::array<int, 6> hay{1, 2, 3, 1, 2, 3};
std::array<int, 2> needle{1, 2};
auto it = find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
return 0;
}
-std=c++20 g_unqualified_stdarray.cpp -o g_unqualified_stdarray_prog
g_unqualified_stdarray.cpp: In function 'int main()':
g_unqualified_stdarray.cpp:6:15: error: 'find_end' was not declared in this scope
6 | auto it = find_end(hay.begin(), hay.end(), needle.begin(), needle.end());
| ^~~~~~~~
g_unqualified_stdarray.cpp:6:15: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
from g_unqualified_stdarray.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:71:1: note: 'std::find_end'
71 | find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
| ^~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:510:34: note: 'std::ranges::find_end'
510 | inline constexpr __find_end_fn find_end{};
| ^~~~~~~~
And with using namespace std; in the file, the qualifier question goes away by a different route - the unqualified call over vectors compiles and runs, because the using-directive brings the name into scope directly:
-std=c++20 g_using_namespace.cpp -o g_using_namespace_prog
$ ./g_using_namespace_prog
The pattern across the probed set is exact: the rescue follows the iterator type, not the container's name - class iterators of std containers carry the name in, pointer iterators do not, whatever container stands behind them - and a using-directive bypasses the question entirely. Write the qualifier either way.
The exact rule
std::find_endis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here, 100 of the other 105 headers in the library's header set - among them<limits>,<ranges>,<vector>,<filesystem>, and<string>- do not declare it, and neither does a file with no include at all; the remaining 5 pull it in transitively, as this library version's behavior, not as a guarantee.'find_end' is not a member of 'std'has one cause in the contexts probed here: the<algorithm>include is missing and nothing else in the file pulled the name in. It comes in one shape only in the sweep probed here: all 100 failing sole headers fail with the plain error line alone, with no suggestion tail, no note lines, and no help lines. No failing sole header produced a different error. And unlike its younger siblings, this name has no standard-based second cause: the classic call dates to C++98 and compiles with the include in place at every probed standard.- In the sweep probed here, 5 headers besides
<algorithm>rescuestd::find_endtransitively -<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, no header besides<algorithm>is required to pullstd::find_endin. - The result rules are the documented ones, as the fixed programs here show: the fixed program prints
result 3 1for the textbook case; the semantics program printslast 3 1,first 0,empty end 6,miss end 6,overlap 1, andmatch 3 -2 calls 1- the call returns an iterator to the start of the last occurrence of the target, overlapping occurrences count, an empty target and a target that never occurs both return the end of the searched range, and the predicate overload decides equality by the given binary predicate. - The classic
std::find_enddates to C++98: with<algorithm>included it compiles and runs as C++98, C++11, C++14, and C++17, each printing3. The layered pieces have floors: the execution-policy overload starts at C++17 - with only<algorithm>included, naming the policy fails with'std::execution' has not been declared; with<execution>included alongside it, the policy call compiles and runs; and compiled as C++14, the same program fails on the policy's name. Constant-expression use starts at C++20: the static-assert program here compiles as C++20 and fails as C++17. - The neighbors all fail in this library:
std::findfails in a sole<vector>file with the suggestiondid you mean 'std::ranges::find'?,std::find_ifwithdid you mean 'std::ranges::find_if'?,std::searchwithdid you mean 'std::ranges::search'?, andstd::adjacent_findwithdid you mean 'std::ranges::adjacent_find'?, whilestd::search_nandstd::find_first_offail there with the plain error - all six are declared by#include <algorithm>by rule, and none of them compiles outright in that file. The fixed neighbor program printsfind_end 3 1,find 2 3,find_if 2 3,search 0 1,search_n 2,adjacent_find -1, andfind_first_of 0 1. - The ranges form of this same name is a function object in namespace
std::ranges, declared in<algorithm>by the standard, needing C++20, returning a subrange of the searched range - compiled as C++17 the ranges program here fails with'std::ranges' has not been declared, and compiled as C++20 it printsranges 3 1 5. In the probes here<ranges>alone does not rescue it in this library - it fails with a not-a-member error naming therangesnamespace for the ranges form,<array>alone fails for it the same way, and<ranges>fails with the plain error for the classic name in the sweep. 'find_end' was not declared in this scopefor an unqualifiedfind_enduse is a different defect: qualify the name asstd::find_end- the include alone does not bring the name out of namespacestd. For this name the unqualified call's fate depends on the iterators' types: over plain arrays it fails, as the first unqualified program above shows; over a vector's iterators and over a list's iterators it is rescued through argument-dependent lookup, as the second and third show, because those iterators arestdclass types; over astd::array's iterators it fails again, because in this library those iterators are plain pointers; and withusing namespace std;in the file it compiles outright, as the last unqualified program shows. Qualify the name either way.
The fixes, ranked
- First, check the include list of the file that names
std::find_end. If<algorithm>is not there, add it - that is the fix for the only cause of this error. It holds whether or not the file happened to compile before through one of the 5 transitive rescues and stopped compiling when its other includes changed - all 100 of the probed failures are this one cause, and every one of them is the plain line, so a missing suggestion tail is not evidence of a different problem. - Second, do not chase a standard upgrade for this error: this name dates to C++98, so a build set to any standard from C++98 up keeps the classic call with the include in place, and the error with the include present is never a standard problem.
- Third, do not hunt for a suggestion to follow: this error carries none in any probed context. The names the neighboring diagnostics offer - the ranges forms of
find,find_if,search, andadjacent_find- belong to other calls in another namespace; a suggestion on a neighbor's error is a spelling guess, not this name's fix. - Fourth, do not reach for a container's header because the call reads a container, or for
<iterator>because the call takes iterators. In the sweep probed here<vector>,<list>,<string>, and<iterator>all fail for this name - none of them is the declaring header by rule. The declaring header is<algorithm>, and a complete program names it alongside the container's own header. - Fifth, do not remove
<algorithm>because a file compiles without it: in the probed set only 5 headers rescue the classic name, and those rescues are not guaranteed - a file that drops the include is one internal-include change away from the error in the first section. - Sixth, do not read an end return as proof the target is absent: an empty target returns the end too, so check the target's length before treating the end as a no-match answer - both are the documented behavior, not defects.
- Seventh, if the error names
std::executioninstead -'std::execution' has not been declared- add<execution>alongside<algorithm>and keep the standard at C++17 or later: this name does have a policy overload, and that pair of changes is the whole fix for the policy form. - Eighth, match the standard to the one piece beyond the classic call that has a floor: constant-expression use needs C++20, and the ranges form needs C++20 - with its header still
<algorithm>by the standard, not<ranges>. - Ninth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::find_endas well - and do not rely on argument-dependent lookup to rescue the unqualified call, because a plain array and astd::arrayeach remove that rescue in the probed set.
Related guides on this site
- 'std::find_if_not' Is Not a Member of 'std' Fix
- 'std::find_if' Is Not a Member of 'std' Fix
- 'std::adjacent_find' Is Not a Member of 'std' Fix
- 'std::find' Is Not a Member of 'std' Fix
Sources
- cppreference, std::find_end - the function templates are defined in
<algorithm>;std::find_endsearches for the last occurrence of the target range in the source range and returns an iterator to its beginning, returning the end of the source range when the target is empty or does not appear, the execution-policy overloads are marked since C++17 and the classic overloads constexpr since C++20, and the complexity is at most the target length times (the source length minus the target length plus 1) comparisons. - cppreference,
<algorithm>header - the header that declares this name and the other algorithm names used as neighbors here. - cppreference, std::ranges::find_end - the C++20 ranges form of this name, a function object in namespace
std::rangesdeclared in<algorithm>, returning a subrange of the searched range.
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.