C++
'std::all_of' Is Not a Member of 'std' Fix
std::all_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 as bare as its neighbors': all 100 failing sole-header contexts give the one plain error line with no suggestion, no notes, and no help at all. This guide pins down the failing shapes, why an empty range answers true, why the predicate stops being applied at the first element that fails it, 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 · 26 min read
- The error: the include is missing
- The textbook version fails too - with the same plain error
- No suggestion in the sweep: not one header offers a wrong name
- 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::all_of is a function template defined in the header <algorithm>. It walks a range once, applying a unary predicate to each element, and returns true if the predicate returns true for every element - and false as soon as one element fails it. It returns a bool and nothing else: it does not modify the range, does not move or erase anything, and hands back no iterator. On an empty range it returns true, because there is no element the predicate fails for. Its classic overload needs only input iterators - the weakest iterator category there is - so it can read a range that can be traversed just once. 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 - 'all_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 - and this name has no trap suggestion in the sweep either, as the sweep section below shows.
But for this name the missing include is not the only cause of the error. std::all_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 as bare as the plainest in its family. Of the 100 failing sole-header contexts probed here, every one fails with the plain line alone - no suggestion tail, no note lines, and no help lines, in any of them. No failing context in the sweep produced a different error at all. 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 every element of a four-element array, 2, 4, 6, 8, is even, but includes only <limits>:
#include <limits>
int main() {
int a[4] = {2, 4, 6, 8};
bool ok = std::all_of(a, a + 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:20: error: 'all_of' is not a member of 'std'
4 | bool ok = std::all_of(a, a + 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:20: error: 'all_of' is not a member of 'std'
3 | bool ok = std::all_of(a, a + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~
The textbook version fails too - with the same plain error
The version most often written first - ask whether every element of a vector is even and print the answer - produces an error in this library, without <algorithm>, and the error is the plain one from the previous section:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 4, 6, 8};
bool ok = std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
std::cout << ok << "\n";
return 0;
}
-std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:20: error: 'all_of' is not a member of 'std'
5 | bool ok = std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~
Nothing rescues the call here and nothing distorts it either: <vector> does not pull the algorithm in - in the sweep below it fails for this name, plainly - and <iostream> pulls in no namesake for this name, so the compiler reports the missing name itself. A program that uses std::all_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
No suggestion in the sweep: not one header offers a wrong name
No header in the sweep decorates this error at all. That sets this name apart from some of its neighbors in the same family: where other names in this family are offered a wrong name to follow in some contexts, std::all_of is offered nothing, in any sole-header context - not a function, not an enumerator, not a type. There is no suggestion to follow and no suggestion to warn against; the diagnostic is the bare line, 100 times over, and the only move it leaves is the right one: name the declaring header.
That absence is itself the useful fact. A reader who has learned to scan these errors for a did you mean tail will find none here, and should not read the silence as a different kind of problem - it is the same missing include, with a library that declares no name spelled near all_of in namespace std itself for the compiler to guess from, in any of the contexts probed here. The suggestions do exist in this family - two of the neighboring names below get them - but they attach to other names, not to this one.
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 every element of 2, 4, 6, 8 is even and requires the answer true, the outcome splits by compile result two ways - the failure in its one diagnostic shape, 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 too: the C++20 ranges library has its own all-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 help line, none produced note lines, and no failing header produced a different error: this name never gets handed to a namesake function, because the standard library has no second function by this name for the call to be measured against.
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, 4, 6, 8};
bool ok = std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
std::cout << "all_even " << ok << "\n";
return 0;
}
-std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
all_even 1
One include, <algorithm>, declares the function - and the textbook program prints all_even 1: every element of 2, 4, 6, 8 is even, so the answer is true, printed as 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, 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 true or false, and stops at the first failure
The call returns one bool, and its two subtleties are both in how that answer is reached. An empty range answers true - there is no element to fail the predicate, so the claim that all elements pass is left standing. And the scan stops early: the first element the predicate fails settles the answer as false, and the predicate is not applied to the elements after it:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 4, 6, 8};
std::cout << "alleven " << std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::vector<int> w = {2, 4, 5, 8};
std::cout << "oneodd " << std::all_of(w.begin(), w.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::vector<int> mt;
std::cout << "empty " << std::all_of(mt.begin(), mt.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::vector<int> one = {7};
std::cout << "singleodd " << std::all_of(one.begin(), one.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::vector<int> two = {10};
std::cout << "singleeven " << std::all_of(two.begin(), two.end(), [](int x) { return x % 2 == 0; }) << "\n";
int calls = 0;
std::vector<int> s = {2, 3, 4, 6};
bool r = std::all_of(s.begin(), s.end(), [&calls](int x) { ++calls; return x % 2 == 0; });
std::cout << "short " << r << " " << calls << "\n";
int calls2 = 0;
std::vector<int> t = {2, 4, 6};
bool r2 = std::all_of(t.begin(), t.end(), [&calls2](int x) { ++calls2; return x % 2 == 0; });
std::cout << "full " << r2 << " " << calls2 << "\n";
return 0;
}
-std=c++20 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
alleven 1
oneodd 0
empty 1
singleodd 0
singleeven 1
short 0 2
full 1 3
Read in order: the alleven line reports 1 - every element of 2, 4, 6, 8 is even. The oneodd line reports 0 for 2, 4, 5, 8: the 5 fails the predicate, and one failure is enough. The empty line reports 1: on an empty range the answer is true, the vacuous case - a reader who expects an empty range to answer false will write a wrong check here, so a range that must be non-empty needs its own emptiness test alongside this call. The singleodd line reports 0 and the singleeven line reports 1: a one-element range is decided by that element alone. The short line reports 0 2 for the range 2, 3, 4, 6: the answer is false, and the counting predicate was applied exactly twice - to the 2, which passes, and to the 3, which fails and ends the scan; the 4 and the 6 were never tested. The full line reports 1 3 for 2, 4, 6: when every element passes, the predicate is applied to all of them, all three, because the answer true is only settled at the end of the range. So the cost of a failing call is the position of the first failure, and the cost of a passing call is the whole range.
Nothing about the range changes along the way: the call reads elements and returns. There is no new logical end to track, no tail to erase, and no size to fix up afterward - the bool is the whole result.
Input iterators: the weakest iterators it accepts
The classic call needs only input iterators - it reads each element once, in order, and never goes back. That is the weakest category any algorithm accepts, and it is why the call can run over a stream, whose iterators cannot be rewound at all:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
int main() {
std::istringstream in("2 4 6 8");
bool ok = std::all_of(std::istream_iterator<int>(in), std::istream_iterator<int>(),
[](int x) { return x % 2 == 0; });
std::cout << "stream " << ok << "\n";
return 0;
}
-std=c++20 r_input.cpp -o r_input_prog
$ ./r_input_prog
stream 1
It reports stream 1 - the four values read from the stream, 2, 4, 6, 8, are all even, and the single pass a stream allows was all the call needed. A list's iterators qualify with room to spare, and the call answers for a list the same way:
-std=c++20 r_list.cpp -o r_list_prog
$ ./r_list_prog
list 1
It reports list 1. The policy overloads ask for forward iterators instead, for a different reason: a parallel execution may need to revisit the range.
Versions: a second cause - the classic call starts at C++11
This call does have a floor, and that is what separates it from the oldest names in its family. std::all_of dates to C++11 - the cppreference page marks the classic overloads since C++11. 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 1, 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:
#include <algorithm>
#include <iostream>
int main() {
int a[4] = {2, 4, 6, 8};
bool ok = std::all_of(a, a + 4, [](int x) { return x % 2 == 0; });
std::cout << ok << "\n";
return 0;
}
-std=c++98 c_version98.cpp -o c_version98_prog
c_version98.cpp: In function 'int main()':
c_version98.cpp:5:20: error: 'all_of' is not a member of 'std'
5 | bool ok = std::all_of(a, a + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~
c_version98.cpp:5:68: warning: lambda expressions only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
5 | bool ok = std::all_of(a, a + 4, [](int x) { return x % 2 == 0; });
| ^
Read the transcript in full: the first 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 the warning underneath it is about the lambda, a second C++11 feature the program uses. 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, 4, 6, 8};
bool ok = std::all_of(std::execution::seq, v.begin(), v.end(), [](int x) { return x % 2 == 0; });
return ok ? 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 ok = std::all_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::all_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 ok = std::all_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, 4, 6, 8};
return std::all_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; });
}
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:23: warning: call to non-'constexpr' function 'bool std::all_of(_IIter, _IIter, _Predicate) [with _IIter = int*; _Predicate = check()::<lambda(int)>]' [-Winvalid-constexpr]
5 | return std::all_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; });
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:458:5: note: 'bool std::all_of(_IIter, _IIter, _Predicate) [with _IIter = int*; _Predicate = check()::<lambda(int)>]' declared here
458 | all_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: two plain failures and two suggestions
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 - there is no side door for it in this library, because the header that declares this family is one <vector> does not pull in. The two siblings of this name - std::any_of, which asks whether the predicate holds for at least one element, and std::none_of, which asks whether it holds for none of them - fail with the plain error:
-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:20: error: 'any_of' is not a member of 'std'
4 | bool ok = std::any_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~
-std=c++20 b_noneof_vector.cpp -o b_noneof_vector_prog
b_noneof_vector.cpp: In function 'int main()':
b_noneof_vector.cpp:4:20: error: 'none_of' is not a member of 'std'
4 | bool ok = std::none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~
While the two search-and-count neighbors fail with suggestions. std::find_if is offered the ranges form of itself:
-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{};
| ^~~~~~~
And std::count_if is offered countr_one, a bit-counting name from a different header entirely:
-std=c++20 b_countif_vector.cpp -o b_countif_vector_prog
b_countif_vector.cpp: In function 'int main()':
b_countif_vector.cpp:4:19: error: 'count_if' is not a member of 'std'; did you mean 'countr_one'?
4 | auto n = std::count_if(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~~~
| countr_one
Neither suggestion is the missing name, and following either one changes the program's meaning: the ranges find_if is a different call shape, and countr_one counts set bits in an integer rather than elements in a range. And no name in the probed set compiles outright in a sole <vector> file - this family has no side door here, unlike some of its neighbors elsewhere in the library. 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, 4, 5, 8:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 4, 5, 8};
std::cout << "all_of " << std::all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::cout << "any_of " << std::any_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) << "\n";
std::cout << "none_of " << std::none_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) << "\n";
auto it = std::find_if(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
std::cout << "find_if " << *it << "\n";
std::cout << "count_if " << std::count_if(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) << "\n";
return 0;
}
-std=c++20 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
all_of 0
any_of 1
none_of 0
find_if 2
count_if 3
Read in order: all_of answers 0, because the 5 is not even; any_of answers 1, because some elements are; none_of answers 0, because it is not true that none are; find_if reports 2, the first element the predicate holds for; and count_if reports 3, the number of elements it holds for. The three all-any-none answers are the three readings of the same scan, and the other two names report where the passing elements are and how many there are.
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::all_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 - not a subrange, not an iterator. Compiled as C++20 it answers for the same vectors:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 4, 6, 8};
bool ok = std::ranges::all_of(v, [](int x) { return x % 2 == 0; });
std::cout << "ranges " << ok << "\n";
std::vector<int> w = {2, 4, 5, 8};
bool ok2 = std::ranges::all_of(w, [](int x) { return x % 2 == 0; });
std::cout << "rangesodd " << ok2 << "\n";
return 0;
}
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
ranges 1
rangesodd 0
The first line reports ranges 1 - every element of 2, 4, 6, 8 is even - and the second reports rangesodd 0 for 2, 4, 5, 8. 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:20: error: 'std::ranges' has not been declared
6 | bool ok = std::ranges::all_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:28: error: 'all_of' is not a member of 'std::ranges'
4 | bool ok = std::ranges::all_of(a, [](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:28: error: 'all_of' is not a member of 'std::ranges'
4 | bool ok = std::ranges::all_of(a, [](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::all_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 a[4] = {2, 4, 6, 8};
bool ok = all_of(a, a + 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:15: error: 'all_of' was not declared in this scope
4 | bool ok = all_of(a, a + 4, [](int x) { return x % 2 == 0; });
| ^~~~~~
g_unqualified.cpp:4: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:30:1: note: 'std::all_of'
30 | all_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:100:32: note: 'std::ranges::all_of'
100 | inline constexpr __all_of_fn all_of{};
| ^~~~~~
That wording - was not declared in this scope, with notes pointing at the declarations of both std::all_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::all_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, 4, 6, 8};
bool ok = all_of(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
return ok ? 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::all_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> a{2, 4, 6, 8};
bool ok = all_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; });
return ok ? 0 : 1;
}
-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:15: error: 'all_of' was not declared in this scope
5 | bool ok = all_of(a.begin(), a.end(), [](int x) { return x % 2 == 0; });
| ^~~~~~
g_unqualified_stdarray.cpp:5: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:30:1: note: 'std::all_of'
30 | all_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:100:32: note: 'std::ranges::all_of'
100 | inline constexpr __all_of_fn all_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::all_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.'all_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 one error line and no suggestion tail, no note lines, and no help lines. No failing sole header produced a different error, and none offered any name at all.- In the sweep probed here, 5 headers besides
<algorithm>rescuestd::all_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::all_ofin. - The result rules are the documented ones, as the fixed programs here show: the fixed program prints
all_even 1for the textbook case; the semantics program printsalleven 1,oneodd 0,empty 1,singleodd 0,singleeven 1,short 0 2, andfull 1 3- the call returnstruewhen the predicate holds for every element,falseat the first element it fails for with the predicate not applied past that element, andtruefor an empty range. - The classic call's iterators need only be input iterators: the stream program here reads its values once through stream iterators and prints
stream 1, and the list program printslist 1. - The classic
std::all_ofdates to C++11: with<algorithm>included it compiles and runs as C++11, C++14, and C++17, each printing1, 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 split in this library:
std::any_ofandstd::none_ofare declared by#include <algorithm>as well and both fail in a sole<vector>file with the plain error;std::find_iffails there with the suggestiondid you mean 'std::ranges::find_if'?andstd::count_ifwithdid you mean 'countr_one'?; and no name in the probed set compiles in that file outright. The fixed neighbor program printsall_of 0,any_of 1,none_of 0,find_if 2, andcount_if 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 sameboolthe classic form returns - compiled as C++17 the ranges program here fails with'std::ranges' has not been declared, and compiled as C++20 it printsranges 1andrangesodd 0for the two vectors. 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 plainly for the classic name in the sweep. 'all_of' was not declared in this scopefor an unqualifiedall_ofuse is a different defect: qualify the name asstd::all_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::all_of. If<algorithm>is not there, add it - that is the fix for the most common cause of this error. It holds whether the file failed plainly - all 100 of the probed failures did - and whether or not it happened to compile before through one of the 5 transitive rescues and stopped compiling when its other includes changed. - 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 wait for a suggestion to confirm the diagnosis: this error offers none for this name, in any probed context. The bare line is the whole diagnostic, and the missing include or the old standard is its whole cause.
- Fourth, do not reach for a container's header because the call reads containers, 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 an empty range to answer
false: it answerstrue, because no element fails the predicate - a range that must be non-empty for the answer to mean anything needs a separate emptiness check next to this call. - Seventh, do not assume the predicate runs over the whole range: it stops at the first element that fails it, as the counting line of the semantics program shows - a predicate written to visit every element, for counting or for side effects, belongs to a different call.
- Eighth, 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. - Ninth, 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>. - Tenth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::all_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::all_ofreturnstrueif the predicate returnstruefor all elements in the range andtruefor an empty range, with at most one application of the predicate per element; the classic overloads are marked since C++11 and constexpr since C++20, and the execution-policy overloads since C++17. - 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>, returningbool.
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.