C++
'std::find_if' Is Not a Member of 'std' Fix
std::find_if lives in one header, <algorithm> - not in <vector>, where the containers it searches live, and not in any header a searching program already has by habit. On this library version a handful of headers rescue it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, <execution>, <functional>, <regex>, and <valarray> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. This error sometimes carries a suggestion - '; did you mean 'find'?' - and that suggestion is a trap: the name it points at is a different function, and in the textbook file it is not even callable over the range. This guide pins down the two failing shapes, the four transitive rescues, and the one include that fixes the error by specification.
Written December 2, 2026 · Tested with GCC 13.3.0 · 24 min read
- The error: the include is missing, in a lean file
- The textbook version fails too - with a suggestion that does not survive being followed
- Neighboring headers: 88 fail plainly, 13 fail with the 'find' suggestion, and four rescue it
- The fix
Written December 2, 2026
Tested with GCC 13.3.0
What this guide is
std::find_if is a function template defined in the header <algorithm>. It returns an iterator to the first element in a range for which the given unary predicate returns true, or the range's end iterator if there is no such element. The range's iterators need only meet the input-iterator requirements - the weakest iterator category any algorithm in this family accepts - the predicate must meet the predicate requirements, and the search applies the predicate at most once per element. The classic overload has existed since C++98 and returns the found iterator itself: there is no count, no flag, and no separate end marker to read.
Because the function lives in one specific header, 'find_if' 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 lines and no help lines at all - but the error line itself splits: most failing files get it bare, and a minority get a suggestion tail namingfind, a different function that does not fix the call, as the textbook section below shows.
Unlike its closest relatives, this name has no second cause in the standard version: the classic std::find_if predates C++11, so a file that includes <algorithm> and is compiled as C++98 calls it successfully - shown in the versions section below. What makes the error worth separating from its relatives is the suggestion. A searching program's file most often already holds <vector> for the container and <iostream> for printing, and in the sweep probed here <vector> fails plainly while <iostream> fails with the find suggestion attached - so the file a reader actually has is the file that gets the misleading version of the error. 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 outcome splits three ways - the plain failure, the suggestion failure, or a rescue - and the rescue set has exactly five entries: <algorithm> itself, <execution>, <functional>, <regex>, and <valarray>.
The error: the include is missing, in a lean file
This program searches a five-element array for the first even element using a free-function predicate, but includes only <limits>:
#include <limits>
bool isEven(int x) { return x % 2 == 0; }
int main() {
int a[5] = {1, 2, 3, 4, 5};
int* it = std::find_if(a, a + 5, isEven);
return it == a + 1 ? 0 : 1;
}
$ g++ -std=c++17 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:5:20: error: 'find_if' is not a member of 'std'
5 | int* it = std::find_if(a, a + 5, isEven);
| ^~~~~~~
That is the whole output: one plain error line, and nothing after it. No suggestion tail rides on the error line itself, there are no note lines, and there are no help lines. The same program with no include at all fails the same way, just as bare, at the same call.
The textbook version fails too - with a suggestion that does not survive being followed
The version most often written first - search a vector with a lambda predicate and print the result - gets the same error, without <algorithm>, but this time the error line carries a tail:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto it = std::find_if(v.begin(), v.end(), [](int x) { return x > 3; });
std::cout << *it << " at " << (it - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++17 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:20: error: 'find_if' is not a member of 'std'; did you mean 'find'?
5 | auto it = std::find_if(v.begin(), v.end(), [](int x) { return x > 3; });
| ^~~~~~~
| find
The tail suggests find. Following it does not work. std::find is a different function - it compares elements against a value, it takes no predicate - and in this file it is not even the algorithm that is visible: the only find name the file can see is a streambuf-iterator overload declared in a library-internal header pulled in by <iostream>, and calling std::find on the vector's iterators in the same file fails on that overload's terms:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto it = std::find(v.begin(), v.end(), 4);
std::cout << *it << " at " << (it - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++17 s_suggested.cpp -o s_suggested_prog
s_suggested.cpp: In function 'int main()':
s_suggested.cpp:5:24: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
5 | auto it = std::find(v.begin(), v.end(), 4);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/locale_facets.h:48,
from /usr/include/c++/13/bits/basic_ios.h:37,
from /usr/include/c++/13/ios:46,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from s_suggested.cpp:1:
/usr/include/c++/13/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
435 | find(istreambuf_iterator<_CharT> __first,
| ^~~~
/usr/include/c++/13/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed:
s_suggested.cpp:5:24: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
5 | auto it = std::find(v.begin(), v.end(), 4);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
What happened: the suggestion is generated because a name spelled find is visible in namespace std in that file - the streambuf-iterator overload - not because the range algorithm is present. The candidate note names that overload and rejects the vector's iterator type for it, so the tail points at a name that is the wrong function, declared for the wrong iterators, in a header the program never included directly. The fix is unchanged by the tail: the predicate search takes <algorithm>, and neither <iostream> nor <vector> rescues it - in the sweep probed here, the only headers that rescue std::find_if besides <algorithm> itself are <execution>, <functional>, <regex>, and <valarray>, and those rescues are properties of this library version, not rules of the language. A program that uses std::find_if includes <algorithm>, whether or not it happens to compile without it.
Neighboring headers: 88 fail plainly, 13 fail with the 'find' suggestion, and four 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 searches a five-element array with a free-function predicate, the outcome splits by compile result and diagnostic shape three ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 88 headers all fail with the plain is not a member of 'std' error line, no suggestion tail on that line, no note lines at all, and no help lines:
<any><array><atomic><barrier><bit><bitset><cassert><cctype><cerrno><cfenv><cfloat><charconv><chrono><cinttypes><ciso646><climits><clocale><cmath><codecvt><compare><concepts><condition_variable><coroutine><csetjmp><csignal><cstdalign><cstdarg><cstdbool><cstddef><cstdint><cstdio><cstdlib><cstring><ctime><cuchar><cwchar><cwctype><deque><exception><expected><format><forward_list><future><initializer_list><iosfwd><latch><limits><list><map><memory><memory_resource><mutex><new><numbers><numeric><optional><queue><random><ranges><ratio><scoped_allocator><semaphore><set><shared_mutex><source_location><span><spanstream><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>
And these 13 headers fail with the same error line plus the suggestion tail ; did you mean 'find'? and a find marker line under the caret - still with no note lines and no help lines:
<ccomplex><complex><ctgmath><filesystem><fstream><iomanip><ios><iostream><istream><iterator><locale><ostream><sstream>
A file with no include at all fails plainly, with the same absence of a tail, notes, and help. No failing sole header prints a note line or a help line anywhere in this sweep.
A sole <vector> file shows the plain shape in full - and <vector> is the header this call is most often expected in, since the container being searched comes from it. It is not there:
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::vector<int>::iterator it = std::find_if(v.begin(), v.end(), isEven);
return it == v.begin() + 1 ? 0 : 1;
}
$ g++ -std=c++17 v_vector.cpp -o v_vector_prog
v_vector.cpp: In function 'int main()':
v_vector.cpp:5:42: error: 'find_if' is not a member of 'std'
5 | std::vector<int>::iterator it = std::find_if(v.begin(), v.end(), isEven);
| ^~~~~~~
And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><execution><functional><regex><valarray>
Two contrasts with the neighboring sweeps are worth holding on to. First, the suggestion class is this name's own shape: the plain class and the suggestion class differ only in the tail on the error line - neither class prints a note line or a help line, and there is no link-failure shape in this sweep, so every failing sole header fails at compile time with the same underlying error. Second, the rescue set has no visible container or iterator shape: the rescues are two execution and functional headers, the regular-expression header, and <valarray> - headers that pull the algorithm header's internals in on the side, which is consistent with a name whose home is the general algorithms header, not the container header its ranges usually come from. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and the other four 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> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto it = std::find_if(v.begin(), v.end(), [](int x) { return x > 3; });
std::cout << *it << " at " << (it - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++17 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
4 at 3
One include, <algorithm>, declares the function - and the search reports 4 at 3: the value 4, the first element of 1 through 10 that is greater than 3, at index 3. The returned iterator is the whole result: dereferencing it gives the element, and subtracting the range's beginning gives its position.
The return value is the result: found, not found, and first-element
The three outcomes of the call are three positions of the one returned iterator. A match partway through the range, a range with no match at all, and a match on the very first element:
#include <algorithm>
#include <iostream>
bool isEven(int x) { return x % 2 == 0; }
int main() {
int a[4] = {1, 3, 4, 6};
int* it = std::find_if(a, a + 4, isEven);
std::cout << *it << " at " << (it - a) << "\n";
int b[3] = {1, 3, 5};
int* it2 = std::find_if(b, b + 3, isEven);
std::cout << (it2 == b + 3 ? "end" : "found") << " " << (it2 - b) << "\n";
int c[3] = {2, 4, 6};
int* it3 = std::find_if(c, c + 3, isEven);
std::cout << *it3 << " at " << (it3 - c) << "\n";
return 0;
}
$ g++ -std=c++17 r_return.cpp -o r_return_prog
$ ./r_return_prog
4 at 2
end 3
2 at 0
Read in order: over 1, 3, 4, 6 the search reports 4 at 2 - the first element the predicate accepts is the third one, because the search stops at the first match and does not continue to the 6 behind it. Over 1, 3, 5, where nothing is even, the return is the end iterator itself, reported as end 3 - one past the last element, the position the caller compares against to detect the miss; dereferencing that iterator is not a result, it is outside the range. And over 2, 4, 6 the first element already qualifies, reported as 2 at 0. Code that uses this function branches on that one comparison - returned iterator against the range's end - and both branches are ordinary outcomes, not errors.
The edge ranges: empty and no match
Neither short range is an error. A search over an empty range returns that range's end at once, and a one-element range whose element does not qualify returns its end the same way:
#include <algorithm>
#include <iostream>
bool isEven(int x) { return x % 2 == 0; }
int main() {
int a[1] = {7};
int* it = std::find_if(a, a, isEven);
std::cout << (it == a ? "empty end" : "found") << "\n";
int* it2 = std::find_if(a, a + 1, isEven);
std::cout << (it2 == a + 1 ? "no match end" : "found") << "\n";
return 0;
}
$ g++ -std=c++17 k_empty.cpp -o k_empty_prog
$ ./k_empty_prog
empty end
no match end
Input iterators: the search runs on a stream
The iterator requirement is the weakest in this family: input iterators suffice, so the range does not need to be a container at all. This program searches a stream of integers read one at a time - a range that cannot be rewound and cannot be indexed - and finds the first even value:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::istringstream in("1 3 4 6");
std::istream_iterator<int> first(in), last;
std::istream_iterator<int> it = std::find_if(first, last, isEven);
std::cout << *it << "\n";
return 0;
}
$ g++ -std=c++17 i_stream.cpp -o i_stream_prog
$ ./i_stream_prog
4
That is a range shape the forward-iterator algorithms in this family cannot run over at all: a stream iterator can be read once, in order, and std::find_if is specified to need nothing more - at most one predicate application per element, in order, stopping at the first match.
Versions: the classic call is C++98; the layers on top are newer
The call itself needs no modern standard. The fixed programs in this guide are compiled as C++17, but the same call, with <algorithm> included, compiles and runs as C++98:
#include <algorithm>
#include <iostream>
bool isEven(int x) { return x % 2 == 0; }
int main() {
int a[5] = {1, 2, 3, 4, 5};
int* it = std::find_if(a, a + 5, isEven);
std::cout << *it << " at " << (it - a) << "\n";
return 0;
}
$ g++ -std=c++98 c_findif98.cpp -o c_findif98_prog
$ ./c_findif98_prog
2 at 1
So when the include is missing, no standard flag rescues the call, and when the include is present, no standard flag is too old for the classic call - the missing-include error is the whole story for the classic overload. The newer pieces are separate overloads and uses layered on top of it. The execution-policy overload is C++17, and it splits the include question in two: the overloads are declared by <algorithm>, but the policy objects live in <execution>, so a policy call with only <algorithm> included fails on the policy's name, not the algorithm's:
#include <algorithm>
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::vector<int>::iterator it = std::find_if(std::execution::seq, v.begin(), v.end(), isEven);
return it == v.begin() + 1 ? 0 : 1;
}
$ g++ -std=c++17 p_policy_algoonly.cpp -o p_policy_algoonly_prog
p_policy_algoonly.cpp: In function 'int main()':
p_policy_algoonly.cpp:6:55: error: 'std::execution' has not been declared
6 | std::vector<int>::iterator it = std::find_if(std::execution::seq, v.begin(), v.end(), isEven);
| ^~~~~~~~~
That wording - has not been declared, naming std::execution - is a different defect with a different missing header: add <execution> alongside <algorithm>, and the same call compiles and runs:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::vector<int>::iterator it = std::find_if(std::execution::seq, v.begin(), v.end(), isEven);
std::cout << *it << " at " << (it - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++17 p_policy_fixed.cpp -o p_policy_fixed_prog
$ ./p_policy_fixed_prog
2 at 1
And since C++20 the classic call is also usable in constant expressions - this program's search runs at compile time, and the assertion on its result is part of the build:
#include <algorithm>
#include <array>
constexpr bool isEven(int x) { return x % 2 == 0; }
constexpr int firstEven() {
std::array<int, 5> a = {1, 2, 3, 4, 5};
auto it = std::find_if(a.begin(), a.end(), isEven);
return it == a.end() ? -1 : *it;
}
static_assert(firstEven() == 2);
int main() { return 0; }
$ g++ -std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog
The neighboring name: find_if_not is not in either
The name std::find_if is paired with does not share the container's home header either. std::find_if_not - the negation, which returns the first element for which the predicate returns false - lives in <algorithm> alongside std::find_if, and it fails in a file whose only include is <vector> with its own plain error and no suggestion tail. It is shown here only as a neighbor, not re-taught:
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {2, 4, 5, 6};
std::vector<int>::iterator it = std::find_if_not(v.begin(), v.end(), isEven);
return it == v.begin() + 2 ? 0 : 1;
}
$ g++ -std=c++17 b_findifnot_vector.cpp -o b_findifnot_vector_prog
b_findifnot_vector.cpp: In function 'int main()':
b_findifnot_vector.cpp:5:42: error: 'find_if_not' is not a member of 'std'
5 | std::vector<int>::iterator it = std::find_if_not(v.begin(), v.end(), isEven);
| ^~~~~~~~~~~
One difference between the neighbors matters for the versions question: std::find_if_not is a C++11 name, where the classic std::find_if is C++98 - so the too-old-standard cause that does not exist for find_if does exist for its negation, and a C++98 file that includes <algorithm> and calls std::find_if_not gets the not-a-member error for the standard's reason, not the include's.
The neighboring names, fixed
The two names together take the same one added header - <algorithm> covers both, and <vector> covers neither algorithm, only the container they search. The fixed neighbor program reports 5 at 2 for the first element that is not even in 2, 4, 5, 6 - the third element, behind two elements the predicate accepts:
#include <algorithm>
#include <iostream>
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {2, 4, 5, 6};
std::vector<int>::iterator it = std::find_if_not(v.begin(), v.end(), isEven);
std::cout << *it << " at " << (it - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++17 b_findifnot_fixed.cpp -o b_findifnot_fixed_prog
$ ./b_findifnot_fixed_prog
5 at 2
The split is the whole lesson of this family: the algorithms take <algorithm> and the container takes <vector>, the two headers are both needed by a complete searching program, and a file that has only the container's header gets the not-a-member error for either algorithm name - plainly for std::find_if_not, and for std::find_if plainly or with the find suggestion tail, depending on what else the file includes.
A different wording - and an argument-dependent rescue that depends on the iterators
Including <algorithm> is not the only half of the name, but for this call the unqualified form splits on its arguments - the range's iterators and the predicate's type. Over plain arrays with a free-function predicate, the unqualified call fails:
#include <algorithm>
bool isEven(int x) { return x % 2 == 0; }
int main() {
int a[5] = {1, 2, 3, 4, 5};
int* it = find_if(a, a + 5, isEven);
return it == a + 1 ? 0 : 1;
}
$ g++ -std=c++17 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:15: error: 'find_if' was not declared in this scope; did you mean 'std::find_if'?
5 | int* it = find_if(a, a + 5, isEven);
| ^~~~~~~
| std::find_if
In file included from /usr/include/c++/13/algorithm:73,
from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:52:1: note: 'std::find_if' declared here
52 | find_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
| ^~~~~~~
That wording - was not declared in this scope, with did you mean 'std::find_if'? on the error line and a note pointing at a declaration - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::find_if; adding includes does not bring the name out of namespace std. (The note happens to point at the execution-policy overload's declaration in a library-internal header - the classic overload is declared in the same home header's internals; the note's target is a detail of this library's layout, not a second home for the name.) Swap the array for a vector, and the same unqualified call compiles and runs:
#include <algorithm>
#include <vector>
bool isEven(int x) { return x % 2 == 0; }
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::vector<int>::iterator it = find_if(v.begin(), v.end(), isEven);
return it == v.begin() + 1 ? 0 : 1;
}
$ g++ -std=c++17 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 vector's iterators are std types, so their associated namespace is std, and lookup finds std::find_if through them. Arrays are fundamental types and have no associated namespace, and a free-function predicate's type has none either, so in the array call above argument-dependent lookup has nothing to find the name from - a predicate argument of a std type, such as a std::function, would give it one and rescue even the array call. Write the qualifier either way.
The exact rule
std::find_ifis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here, every one of the other 101 headers in the library's header set - among them<vector>,<iostream>,<numeric>,<string>, and<version>- does not declare it, and neither does a file with no include at all.'find_if' is not a member of 'std'means the<algorithm>include is missing and nothing else in the file pulled the name in. In the sweep probed here the failing shape splits two ways: 88 sole headers fail with one plain error line - no suggestion tail, no note lines, no help lines - and 13 sole headers add the suggestion tail; did you mean 'find'?with afindmarker line, and still no note lines and no help lines. No probed sole header produces a note class or a declared-but-not-defined link-failure shape for this name.- The suggestion tail is not a fix.
std::findis a different function - it compares elements against a value and takes no predicate - and in the textbook file probed here the onlyfindname visible is a streambuf-iterator overload from a library-internal header, so callingstd::findon the vector's iterators in that file fails withno matching function for call to 'find'and candidate notes naming that overload. - In the sweep probed here, four headers besides
<algorithm>rescuestd::find_iftransitively -<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_ifin. - The result rules are the documented ones, as the fixed programs here show: the fixed program prints
4 at 3for the first element greater than 3 in the population 1 through 10; over 1, 3, 4, 6 the search prints4 at 2, the first element the predicate accepts; and when no element qualifies the return is the end iterator itself - over 1, 3, 5 the program printsend 3. The returned iterator is compared against the range's end to tell a match from a miss, and the end iterator itself is never a match. - The edge ranges are ordinary: searching an empty range or a one-element range with no match returns that range's end - the edge program here prints
empty endandno match end- because the return contract has the end position for exactly those cases. - The classic
std::find_ifis a C++98 function: it compiles and runs as C++98 with<algorithm>included, reporting2 at 1, and it is usable in constant expressions since C++20. There is no too-old-standard second cause for the classic call. The execution-policy overload is C++17 and needs two headers:<algorithm>for the overload and<execution>for the policy objects - with only<algorithm>included, namingstd::execution::seqfails with'std::execution' has not been declared. - The range's iterators must meet the input-iterator requirements and the predicate must meet the predicate requirements; the predicate is applied at most once per element. The stream program here shows the floor in action: over a stream of integers read one at a time, the search prints
4, the first even value. std::find_if_notis not declared by#include <vector>: in the program here, which includes only<vector>, it gets its ownis not a member of 'std'error, plain, with no suggestion tail - and the fixed neighbor program, which includes both<algorithm>and<vector>, prints5 at 2for the negation call.std::find_if_notis a C++11 name, so for that name a standard before C++11 is a real second cause.'find_if' was not declared in this scopefor an unqualifiedfind_ifuse is a different defect: qualify the name asstd::find_if- the include alone does not bring the name out of namespacestd. For this name the unqualified call's fate depends on its arguments: over plain arrays with a free-function predicate it fails, as the first unqualified program above shows, and over a vector's iterators it is rescued through argument-dependent lookup, as the second shows, because those iterators arestdtypes - and a predicate argument of astdtype rescues the array call through the predicate argument the same way. Qualify the name either way.
The fixes, ranked
- First, check the include list of the file that names
std::find_if. If<algorithm>is not there, add it - that is the fix in the common case, and it holds whether the file failed plainly in a lean context, failed with the suggestion tail in a textbook file, or happened to compile before through a transitive rescue. - Second, do not follow the
findsuggestion when it appears. In the contexts probed here the suggested name is a different function that takes a value instead of a predicate - and in the textbook file it is not callable over the range at all, failing withno matching function for call to 'find'. Take the fix from the name's home header,<algorithm>, not from the tail. - Third, do not reach for
<vector>because the call searches a container. In the sweep probed here,<vector>fails forstd::find_ifwith the plain error - the container and the algorithm live in different headers,std::vectorin<vector>andstd::find_ifin<algorithm>, and a complete program needs both. - Fourth, do not be reassured by
<iostream>being present - in the sweep here it fails too, with the suggestion tail attached - and do not remove<algorithm>because a file compiles without it: in the probed set four headers rescue it, and those rescues are not guaranteed. - Fifth, if the error names
std::executioninstead -'std::execution' has not been declared- the missing header is the other one: add<execution>alongside<algorithm>. That error appears only on the policy overload's path; the classic call never names it. - Sixth, do not chase the standard flag for the classic call. With
<algorithm>included it compiles as C++98; the flag matters only for the layered pieces - the execution-policy overload needs C++17,std::find_if_notneeds C++11, and constant-expression use needs C++20. - Seventh, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::find_ifas well - and do not rely on astdcontainer's iterators to rescue the unqualified call through argument-dependent lookup, because an array range removes that rescue. - Eighth, if the failing name is the neighboring one, the fix is the same header:
find_if_nottakes an added<algorithm>too - one header for both algorithm names, and<vector>for the container alone.
Which fix for which cause
#include <algorithm>missing,std::find_ifused in a file whose only include is one of the 88 headers listed as failing plainly in the sweep section above, or that includes nothing: the message is'find_if' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add#include <algorithm>.#include <algorithm>missing,std::find_ifused in a file whose only include is one of the 13 headers listed as failing with the suggestion in the sweep section above: the message is'find_if' is not a member of 'std'; did you mean 'find'?- add#include <algorithm>, and do not switch the call tostd::find.std::find_ifused in a textbook file including<iostream>and<vector>: the message is the error with thefindtail - add#include <algorithm>.std::find_ifused with only<algorithm>,<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 other four rescues are not guaranteed.std::find_ifcalled with an execution policy,<algorithm>included but<execution>not: the message is'std::execution' has not been declared- add#include <execution>alongside<algorithm>, and compile as C++17 or later.- The classic
std::find_ifcall with<algorithm>included under any standard from C++98 on: no error - the classic call predates C++11, so a persistent not-a-member error with the include present points back at the include's file, not the flag. std::find_if_notused without<algorithm>in a file whose only include is<vector>: the message namesfind_if_not, plainly, with no suggestion tail - add#include <algorithm>. For that name the header is the same one, and the standard must be C++11 or later.find_ifused without thestd::qualifier,<algorithm>included, over array arguments with a free-function predicate: the message is'find_if' was not declared in this scope; did you mean 'std::find_if'?- qualify the name asstd::find_if. Over a vector's iterators the same unqualified call compiles through argument-dependent lookup - qualify it anyway, so the call does not depend on the range's iterator type.
Checklist
- Check the include list of the file that names the call, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Do not read a suggestion tail as a fix direction. For this name the tail, when it appears, names
find- a different function - and in the textbook file probed here that name is not callable over the range at all. - Do not import the container's header into this error:
find_ifandfind_if_nottake<algorithm>andstd::vectortakes<vector>, so there are two headers in a complete searching program, one for the algorithms and one for the container. - 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::find_ifat all, and the four headers that do rescue it do so only transitively. - Match the standard to the piece you are using, not to the classic call: the classic call needs only C++98 and
<algorithm>; the policy overload needs C++17 and<execution>as well;std::find_if_notneeds C++11; constant-expression use needs C++20. - Compare the returned iterator against the range's end before dereferencing it: the end return is the not-found answer, not an element. The fixed programs here print
4 at 3for the found case andend 3for the miss. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
4 at 3for the ten-element search,4 at 2,end 3, and2 at 0for the return-value cases,2 at 1for the C++98 and policy calls,4for the stream search, and5 at 2for the neighbor negation call.
Related guides
- 'std::find' Is Not a Member of 'std' Fix - the same missing-include shape for the value-search sibling in the same header:
std::findcompares elements against a value wherestd::find_ifapplies a predicate, and it is the very name this guide's suggestion tail points at - where the two guides agree is that the suggested name is itself an<algorithm>name with the same home header, so neither call is fixed by the other's spelling. - 'std::search' Is Not a Member of 'std' Fix - the same missing-include shape for the subsequence-search name in this family, with the same five-entry rescue set: its sweep splits into plain failures, a
bsearchsuggestion class, and the same four transitive rescues - and the two calls differ in their iterator floor, sincestd::searchneeds forward iterators wherestd::find_ifruns on input iterators, down to a stream read one element at a time.
Sources
- cppreference,
std::find,std::find_if,std::find_if_not— forstd::find_ifbeing a function template defined in<algorithm>; for the classic overload carrying no since-version marker of its own - it predates C++11, with the page's defect report against C++98 - whilestd::find_if_notis marked since C++11; for the execution-policy overloads being since C++17 and the classic overloads being constexpr since C++20; for the return being the first iterator for which the predicate returnstrue, orlastif there is no such iterator; for the iterators needing to meet the input-iterator requirements and the predicate the predicate requirements, with the predicate expression needing to be convertible tobooland not modifying its argument; for the complexity being at most one predicate application per element; and for the note that, where C++11 is not available, an equivalent tostd::find_if_notisstd::find_ifwith the negated predicate. - cppreference, Standard library header
<algorithm>— for<algorithm>being the header whose synopsis declaresstd::find,std::find_if, andstd::find_if_not, the home-header fact both the fix and the neighbor sections of this guide rest on.
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.