C++
'std::none_of' Is Not a Member of 'std' Fix
std::none_of 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's diagnostic is the plainest in its family: not one of the 100 failing sole-header contexts decorates the error with a suggestion, so there is no wrong name to follow - and no hint where the right one lives either. This guide pins down the failing shapes, why a single passing element settles the answer, why an empty range answers true, why a C++98 build keeps this same error even with the include in place, and the include that fixes the ordinary case by rule.
Written December 3, 2026 · Tested with GCC 13.3.0 · 25 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::none_of is a function template defined in the header <algorithm>. It walks a range applying a unary predicate to each element and returns a bool: true exactly when the predicate returns false for every element - when none of the elements passes the test - and false as soon as one element passes. It writes nothing and modifies nothing; the whole answer is the returned bool. Its classic overload needs only input iterators, and the predicate is applied at most once per element: the scan may stop at the first element the predicate passes, because that one element already settles the answer false, so a range where nothing passes is the only shape that is scanned to the end. An empty range answers true - no element passes, vacuously. The classic call dates to C++11, 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 - 'none_of' is not a member of 'std' is usually 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.
But for this name the missing include is not the only cause of the error. std::none_of starts at C++11, so a file compiled as C++98 sees the very same wording even with <algorithm> included, because the name does not exist at that standard - the versions section below shows that transcript. The pieces layered on top 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 the plainest in its family: 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 asks whether no element of a four-element array, 2, 3, 4, 6, is even, but includes only <limits>:
#include <limits>
int main() {
int src[4] = {2, 3, 4, 6};
bool r = std::none_of(src, src + 4, [](int x) { return x % 2 == 0; });
return 0;
}
-std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:19: error: 'none_of' is not a member of 'std'
4 | bool r = std::none_of(src, src + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~~
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:3:19: error: 'none_of' is not a member of 'std'
3 | bool r = std::none_of(src, src + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~~
The textbook version fails too - with no suggestion at all
The version most often written first - ask the question over a vector and print the answer - 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> v = {2, 3, 4, 6};
bool r = std::none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
std::cout << (r ? "true" : "false") << "\n";
return 0;
}
-std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:19: error: 'none_of' is not a member of 'std'
5 | bool r = std::none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~
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: unlike its copying neighbors, whose diagnostics offer a shorter real name, this name's error offers nothing, so the only move it leaves is the right one. A program that uses std::none_of 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 none_of, 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 asks whether no element of 2, 3, 4, 6 is even and requires the answer false 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 none-of 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> v = {2, 3, 4, 6};
bool r = std::none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
std::cout << "result " << (r ? "true" : "false") << "\n";
return 0;
}
-std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
result false
One include, <algorithm>, declares the function - and the textbook program prints result false: of 2, 3, 4, 6, the very first element is even, so it is not true that none of them is. 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, as long as the standard is C++11 or later; the one case where it is not is the C++98 case in the versions section below.
What the call does: it answers a yes-no question, and one passing element settles it
The call's whole result is the returned bool, and the scan behind it is lazy in one direction: the moment an element passes the predicate, the answer is false and the remaining elements are never tested. Only a range where nothing passes is scanned to the end - that is the one shape where the answer true has to be earned element by element. The counting predicate in this program records exactly how far each scan got:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
int calls = 0;
auto even = [&calls](int x) { ++calls; return x % 2 == 0; };
std::vector<int> v0 = {2, 3, 4, 6};
calls = 0;
bool r0 = std::none_of(v0.begin(), v0.end(), even);
std::cout << "mixed " << (r0 ? "true" : "false") << " calls " << calls << "\n";
std::vector<int> v1 = {3, 4, 5};
calls = 0;
bool r1 = std::none_of(v1.begin(), v1.end(), even);
std::cout << "second " << (r1 ? "true" : "false") << " calls " << calls << "\n";
std::vector<int> v2 = {3, 5, 7};
calls = 0;
bool r2 = std::none_of(v2.begin(), v2.end(), even);
std::cout << "none " << (r2 ? "true" : "false") << " calls " << calls << "\n";
std::vector<int> v3 = {};
calls = 0;
bool r3 = std::none_of(v3.begin(), v3.end(), even);
std::cout << "empty " << (r3 ? "true" : "false") << " calls " << calls << "\n";
return 0;
}
-std=c++20 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
mixed false calls 1
second false calls 2
none true calls 3
empty true calls 0
Read in order: the mixed line reports false with calls 1 - over 2, 3, 4, 6 the first element, 2, already passes the even test, so the answer is settled after a single application and 3, 4, 6 are never tested. The second line reports false with calls 2: over 3, 4, 5 the scan passes over the odd 3 and stops at the even 4 - the stop follows the first passing element wherever it sits, not the range's start. The none line reports true with calls 3: over 3, 5, 7 no element passes, so all three are tested before the call can answer true - a true answer from this call always costs a full scan. The empty line reports true with calls 0: an empty range has no passing element by definition, so the answer is true with the predicate never applied at all. That vacuous true is the case readers most often get backwards - none_of on an empty range does not fail or answer false; it answers true, because there is nothing in the range that passes.
The cost rule follows from the same shape: the predicate is applied at most once per element - at most the length of the range - and usually fewer times, because the first passing element ends the scan.
Versions: a second cause - the classic call starts at C++11
This call does have a floor. std::none_of dates to C++11 - the cppreference page marks the classic overload since C++11, and there is no earlier form of it. The fixed programs in this guide are compiled as C++20, but the floor is far below that: with <algorithm> included, the same question compiled as C++11 compiles and runs, printing false, and as C++14 and as C++17 the same way. One standard level lower, the picture flips - compiled as C++98, the same program, include and all, fails with this guide's own error. The C++98 transcript uses a named functor instead of a lambda, so the only C++11 feature left in the file is the call itself:
#include <algorithm>
#include <iostream>
struct Even { bool operator()(int x) const { return x % 2 == 0; } };
int main() {
int src[4] = {2, 3, 4, 6};
bool r = std::none_of(src, src + 4, Even());
std::cout << (r ? "true" : "false") << "\n";
return 0;
}
-std=c++98 c_version98.cpp -o c_version98_prog
c_version98.cpp: In function 'int main()':
c_version98.cpp:6:19: error: 'none_of' is not a member of 'std'
6 | bool r = std::none_of(src, src + 4, Even());
| ^~~~~~~
Read the transcript in full: the one error is the plain not-a-member line itself - at C++98 the name is not a member of std because it does not exist yet, and with the functor in place there is not even a lambda warning underneath it. Raising the standard to C++11 or later is the whole fix for that shape; no include change reaches it. So this name's error has two causes, not one: a missing <algorithm>, or a standard older than C++11 - and the two are told apart by checking whether the include is already in the file. A file that includes <algorithm>, compiles at C++11 or later, and still sees this error does not have either problem; the include is not reaching the file that names the call, or the name in the file is not 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> v = {2, 3, 4, 6};
bool r = std::none_of(std::execution::seq, v.begin(), v.end(), [](int x) { return x % 2 == 0; });
return (r == false) ? 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:5:32: error: 'std::execution' has not been declared
5 | bool r = std::none_of(std::execution::seq, v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~~~
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::none_of 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:6:32: error: 'std::execution' has not been declared
6 | bool r = std::none_of(std::execution::seq, v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~~~
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 bool check() {
std::array<int, 4> a{2, 3, 4, 6};
return std::none_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; }) == false;
}
static_assert(check());
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 bool check()':
c_constexpr17.cpp:5:24: warning: call to non-'constexpr' function 'bool std::none_of(_IIter, _IIter, _Predicate) [with _IIter = int*; _Predicate = check()::<lambda(int)>]' [-Winvalid-constexpr]
5 | return std::none_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; }) == false;
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:476:5: note: 'bool std::none_of(_IIter, _IIter, _Predicate) [with _IIter = int*; _Predicate = check()::<lambda(int)>]' declared here
476 | none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
| ^~~~~~~
c_constexpr17.cpp: At global scope:
c_constexpr17.cpp:7:20: error: non-constant condition for static assertion
7 | static_assert(check());
| ~~~~~^~
c_constexpr17.cpp:7:20: error: 'constexpr bool check()' called in a constant expression
c_constexpr17.cpp:3:16: note: 'constexpr bool check()' declared here
3 | constexpr bool 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++11 up.
The neighboring names: all four fail, two with suggestions that are not this family
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 four ways - no member of it compiles at all. std::all_of, which answers true only when every element passes, fails with the plain error:
-std=c++20 b_allof_vector.cpp -o b_allof_vector_prog
b_allof_vector.cpp: In function 'int main()':
b_allof_vector.cpp:4:19: error: 'all_of' is not a member of 'std'
4 | bool r = std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~
std::any_of - the mirror sibling, which answers true when at least one element passes - fails with the plain error too:
-std=c++20 b_anyof_vector.cpp -o b_anyof_vector_prog
b_anyof_vector.cpp: In function 'int main()':
b_anyof_vector.cpp:4:19: error: 'any_of' is not a member of 'std'
4 | bool r = std::any_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~
std::copy_if, which writes the passing elements to a destination, fails with a suggestion - and the suggestion is the unfiltered copy:
-std=c++20 b_copyif_vector.cpp -o b_copyif_vector_prog
b_copyif_vector.cpp: In function 'int main()':
b_copyif_vector.cpp:5:22: error: 'copy_if' is not a member of 'std'; did you mean 'copy'?
5 | auto last = std::copy_if(v.begin(), v.end(), out.begin(), [](int x) { return x % 2 == 0; });
| ^~~~~~~
| copy
While std::find_if, which returns an iterator to the first passing element instead of a bool, fails with a suggestion that points into the ranges library:
-std=c++20 b_findif_vector.cpp -o b_findif_vector_prog
b_findif_vector.cpp: In function 'int main()':
b_findif_vector.cpp:4:20: error: 'find_if' is not a member of 'std'; did you mean 'std::ranges::find_if'?
4 | auto it = std::find_if(v.begin(), v.end(), [](int x) { return x % 2 != 0; });
| ^~~~~~~
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{};
| ^~~~~~~
No suggestion in this set is a member of this guide's family: copy copies every element with no predicate, and std::ranges::find_if is a different name in a different namespace that returns an iterator, not a bool. And unlike the copying family, where one neighbor compiles outright in this file through an internal include, here nothing compiles - all four names wait for the same header. The failing neighbors are shown here only as neighbors, not re-taught.
The neighboring names, fixed
Together the five 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 five operations over the range 2, 3, 4, 6:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 3, 4, 6};
auto even = [](int x) { return x % 2 == 0; };
std::cout << "none_of " << (std::none_of(v.begin(), v.end(), even) ? "true" : "false") << "\n";
std::cout << "all_of " << (std::all_of(v.begin(), v.end(), even) ? "true" : "false") << "\n";
std::cout << "any_of " << (std::any_of(v.begin(), v.end(), even) ? "true" : "false") << "\n";
std::vector<int> cf(4);
auto cfl = std::copy_if(v.begin(), v.end(), cf.begin(), even);
std::cout << "copy_if " << (cfl - cf.begin()) << " " << cf[0] << " " << cf[1] << " " << cf[2] << "\n";
auto fit = std::find_if(v.begin(), v.end(), [](int x) { return x % 2 != 0; });
std::cout << "find_if " << (fit - v.begin()) << " " << *fit << "\n";
return 0;
}
-std=c++20 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
none_of false
all_of false
any_of true
copy_if 3 2 4 6
find_if 1 3
Read in order: none_of reports false - 2 passes the even test, so it is not true that none pass. all_of reports false as well, from the other side: 3 fails the test, so not all pass. any_of reports true - at least one element passes. copy_if reports a count of 3 and the elements 2 4 6 themselves. And find_if, handed the opposite predicate, reports position 1 and the value 3 - the first element that fails the even test, which is the element whose existence makes both none_of and all_of answer false here.
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::none_of is a function object in the ranges namespace, declared in <algorithm>, that accepts a whole range and returns the same bool the classic form returns - there is no result object to unpack for this family. Compiled as C++20 it answers for the same vector:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 3, 4, 6};
bool r = std::ranges::none_of(v, [](int x) { return x % 2 == 0; });
std::cout << "ranges " << (r ? "true" : "false") << "\n";
return 0;
}
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
ranges false
The ranges line reports false - the same answer the classic form gives over 2, 3, 4, 6. 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:6:19: error: 'std::ranges' has not been declared
6 | bool r = std::ranges::none_of(v, [](int x) { return x % 2 == 0; });
| ^~~~~~
And in this library the ranges header does not rescue the ranges form - a file whose only include is <ranges> 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:4:27: error: 'none_of' is not a member of 'std::ranges'
4 | bool r = std::ranges::none_of(src, [](int x) { return x % 2 == 0; });
| ^~~~~~~
-std=c++20 r_ranges_arrayonly.cpp -o r_ranges_arrayonly_prog
r_ranges_arrayonly.cpp: In function 'int main()':
r_ranges_arrayonly.cpp:4:27: error: 'none_of' is not a member of 'std::ranges'
4 | bool r = std::ranges::none_of(src, [](int x) { return x % 2 == 0; });
| ^~~~~~~
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::none_of 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 src[4] = {2, 3, 4, 6};
bool r = none_of(src, src + 4, [](int x) { return x % 2 == 0; });
return 0;
}
-std=c++20 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:4:14: error: 'none_of' was not declared in this scope
4 | bool r = none_of(src, src + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~~
g_unqualified.cpp:4:14: 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:36:1: note: 'std::none_of'
36 | none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
| ^~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:156:33: note: 'std::ranges::none_of'
156 | inline constexpr __none_of_fn none_of{};
| ^~~~~~~
That wording - was not declared in this scope, with notes pointing at the declarations of both std::none_of 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::none_of; adding includes does not bring the name out of namespace std. Swap the arrays for a vector, and the same unqualified call compiles and runs:
#include <algorithm>
#include <vector>
int main() {
std::vector<int> v = {2, 3, 4, 6};
bool r = none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
return (r == false) ? 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 vector's iterators are std types, so their associated namespace is std, and lookup finds std::none_of through them. A list's iterators rescue it the same way - the same unqualified call over a list 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, 4> src{2, 3, 4, 6};
bool r = none_of(src.begin(), src.end(), [](int x) { return x % 2 == 0; });
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:5:14: error: 'none_of' was not declared in this scope
5 | bool r = none_of(src.begin(), src.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~
g_unqualified_stdarray.cpp:5:14: 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:36:1: note: 'std::none_of'
36 | none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
| ^~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:156:33: note: 'std::ranges::none_of'
156 | inline constexpr __none_of_fn none_of{};
| ^~~~~~~
And with using namespace std; in the file, the qualifier question goes away by a different route - the unqualified call over a vector 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::none_ofis 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.'none_of' is not a member of 'std'has two causes in the contexts probed here: the<algorithm>include is missing and nothing else in the file pulled the name in, or the program is compiled as C++98, where the name does not exist - and 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.- In the sweep probed here, 5 headers besides
<algorithm>rescuestd::none_oftransitively -<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::none_ofin. - The result rules are the documented ones, as the fixed programs here show: the fixed program prints
result falsefor the textbook case; the semantics program printsmixed false calls 1,second false calls 2,none true calls 3, andempty true calls 0- the call returnstrueexactly when no element passes the predicate, stops applying the predicate at the first passing element, applies it to every element when none passes, and answerstruewith no applications on an empty range. - The classic
std::none_ofdates to C++11: with<algorithm>included it compiles and runs as C++11, C++14, and C++17, each printingfalse, and compiled as C++98 it fails with the same not-a-member error, include and all. 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::all_ofandstd::any_offail in a sole<vector>file with the plain error,std::copy_iffails there with the suggestiondid you mean 'copy'?, andstd::find_iffails there with the suggestiondid you mean 'std::ranges::find_if'?- all four are declared by#include <algorithm>by rule, and none of them compiles outright in that file. The fixed neighbor program printsnone_of false,all_of false,any_of true,copy_if 3 2 4 6, andfind_if 1 3. - 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 the sameboolas the classic form - compiled as C++17 the ranges program here fails with'std::ranges' has not been declared, and compiled as C++20 it printsranges false. 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. 'none_of' was not declared in this scopefor an unqualifiednone_ofuse is a different defect: qualify the name asstd::none_of- 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::none_of. If<algorithm>is not there, add it - that is the fix for the most common 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, if
<algorithm>is already there, check the standard: this name starts at C++11, so a build set to C++98 keeps the error with the include in place, and raising the standard to C++11 or later is the whole fix for that shape. - Third, do not hunt for a suggestion to follow: this error carries none in any probed context. The names the neighboring diagnostics offer -
copyforcopy_if,std::ranges::find_ifforfind_if- belong to other calls with other return types; 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 expect a
trueanswer to be cheap, and do not special-case the empty range as an error: atrueanswer means the predicate ran over the whole range, and an empty range answerstruewith the predicate never applied - 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::none_ofas 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::unique' Is Not a Member of 'std' Fix
- 'std::search_n' Is Not a Member of 'std' Fix
- 'std::replace' Is Not a Member of 'std' Fix
- 'std::remove' Is Not a Member of 'std' Fix
Sources
- cppreference, std::all_of, std::any_of, std::none_of - the function templates are defined in
<algorithm>;std::none_ofreturnstrueif the predicate returnsfalsefor all elements in the range, the classic overloads are marked since C++11 and constexpr since C++20, the execution-policy overloads since C++17, and the complexity is at most the range's length in predicate applications. - cppreference,
<algorithm>header - the header that declares this name and the other algorithm names used as neighbors here. - cppreference, std::ranges::all_of, std::ranges::any_of, std::ranges::none_of - the C++20 ranges forms of these names, function objects in namespace
std::rangesdeclared in<algorithm>, returning the same bool as the classic forms.
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.