C++
'std::reduce' Is Not a Member of 'std' Fix
std::reduce lives in one header, <numeric> - and on this library version almost nothing rescues it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, only <execution> and <random> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. Unlike most of its siblings in this family, this error offers no note at all - no header is named, no include is suggested - so the fix has to come from knowing the name's home. This guide pins down the one failing shape, the two transitive rescues, and the one include that fixes the error by specification.
Written December 2, 2026 · Tested with GCC 13.3.0 · 23 min read
- The error: the include is missing, in a lean file
- The textbook version fails too - with no note to follow
- Neighboring headers: 103 fail the same way, and two rescue it
- The fix
Written December 2, 2026
Tested with GCC 13.3.0
What this guide is
std::reduce is a function template defined in the header <numeric>. It reduces a range to a single value: the overloads without a policy add the elements with std::plus<>() by default, or combine them with a binary operation the program passes, starting from an initial value the program passes or from a value-initialized element. It has existed since C++17, its non-policy overloads are constexpr since C++20, and it differs from its older sibling std::accumulate in one load-bearing way: the elements may be grouped and combined in an unspecified order, which is what makes the execution-policy overloads - the same call with a std::execution policy as the first argument - possible, and what makes the result non-deterministic when the operation is not associative and commutative.
Because the template lives in one specific header, 'reduce' is not a member of 'std' has one common cause:
- The
#include <numeric>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 suggestion tail on the error line, no help lines - and no note lines at all. That silence is this error's distinguishing trait in its family: its siblingstd::invokegets a note naming its home header behind every failing header, whilestd::reducegets nothing, behind every failing header and in a file with no include at all. The fix has to come from the name's home header, not from the diagnostic.
What makes this error worth separating from its relatives is the shape of the sweep behind it. The sweep probed here covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits only two ways - the one uniform failure, or a rescue - and the rescue set has exactly three entries: <numeric> itself, <execution>, and <random>. The older siblings in this family - std::invoke and std::min_element among them - have their own guides and are linked at the end, not re-taught here.
The error: the include is missing, in a lean file
This program returns success if reducing the array 10, 20, 5, 7 with an initial value of 0 gives 42, but includes only <limits>:
#include <limits>
int main() {
int a[4] = {10, 20, 5, 7};
return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:17: error: 'reduce' is not a member of 'std'
4 | return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~
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:
int main() {
int a[4] = {10, 20, 5, 7};
return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:17: error: 'reduce' is not a member of 'std'
3 | return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~
The textbook version fails too - with no note to follow
The version most often written first - print the sum of a vector, with std::cout - gets the same error, without <numeric>, and the same silence after it:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << std::reduce(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:23: error: 'reduce' is not a member of 'std'
5 | std::cout << std::reduce(v.begin(), v.end(), 0) << "\n";
| ^~~~~~
What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one - and there is no note pointing anywhere. In the sweep probed here, the only headers that rescue std::reduce besides <numeric> itself are <execution> and <random>, and those rescues are properties of this library version, not rules of the language. A program that uses std::reduce includes <numeric>, whether or not it happens to compile without it.
Neighboring headers: 103 fail the same way, and two 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 returns success if reducing the array 10, 20, 5, 7 with an initial value of 0 gives 42, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 103 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:
<algorithm><any><array><atomic><barrier><bit><bitset><cassert><ccomplex><cctype><cerrno><cfenv><cfloat><charconv><chrono><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><functional><future><initializer_list><iomanip><ios><iosfwd><iostream><istream><iterator><latch><limits><list><locale><map><memory><memory_resource><mutex><new><numbers><optional><ostream><queue><ranges><ratio><regex><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><valarray><variant><vector><version>
A file with no include at all fails the same way, with the same absence of notes. No failing sole header prints a suggestion tail, a note line, or a help line in this sweep.
A sole <algorithm> file shows the failing shape in full - and <algorithm> is the header this call is most often expected in, since std::accumulate's parallel-era sibling reads like an algorithm. It is not there:
#include <algorithm>
int main() {
int a[4] = {10, 20, 5, 7};
return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 v_algorithm.cpp -o v_algorithm_prog
v_algorithm.cpp: In function 'int main()':
v_algorithm.cpp:4:17: error: 'reduce' is not a member of 'std'
4 | return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~
And these headers rescue the program - it compiles and runs with no <numeric> anywhere in the file:
<execution><numeric><random>
Two contrasts with the neighboring sweeps are worth holding on to. First, there is no note class, no suggestion class, and no link-failure shape in this sweep: every failing sole header fails at compile time with the same bare error, so the header-naming notes that std::invoke carries - and the declared-but-not-defined link failure that std::swap produces behind five headers - have no counterpart for this name in the probed set. Second, the rescue set is small and odd: where std::min_element is rescued transitively by five headers besides its home, std::reduce is rescued by two, <execution> and <random>. <numeric> - the home header - is on the rescue list by definition, not by transitivity, and the other two rescues are this library version's behavior, not a guarantee.
The fix
Add the header:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << std::reduce(v.begin(), v.end()) << " "
<< std::reduce(v.begin(), v.end(), 0) << " "
<< std::reduce(v.begin(), v.end(), 1, [](int x, int y) { return x * y; }) << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
42 42 7000
One include, <numeric>, declares the template: the no-init overload and the init overload both sum the four values to 42, and the operation overload multiplies them from an initial 1 - 10 × 20 × 5 × 7 - and reports 7000, so the three calls are three different computations, not one answer repeated.
The fixed programs: order is not promised, and strings work
std::reduce is std::accumulate with the order guarantee removed. Running both over the same values with the same operation shows what that means: with subtraction - an operation that is neither associative nor commutative - the left fold and the reduction give different answers, and both are correct under their own rules:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {100, 10, 5, 1};
auto sub = [](int x, int y) { return x - y; };
std::cout << std::accumulate(v.begin(), v.end(), 0, sub) << " "
<< std::reduce(v.begin(), v.end(), 0, sub) << "\n";
return 0;
}
$ g++ -std=c++20 k_order.cpp -o k_order_prog
$ ./k_order_prog
-116 -86
Read in order: std::accumulate folds strictly left to right - (((0 − 100) − 10) − 5) − 1 - and reports -116. std::reduce groups the elements in an order this library version chose and reports -86 here. Neither is a bug: the reduction's contract allows any grouping, so an operation whose result depends on grouping gives a result that depends on the grouping. Addition and multiplication do not care; subtraction, division, and floating-point addition do.
The operation is not limited to numbers. A reduce over strings with a string initial value concatenates them:
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
int main() {
std::vector<std::string> v = {"a", "b", "c"};
std::cout << std::reduce(v.begin(), v.end(), std::string("")) << "\n";
return 0;
}
$ g++ -std=c++20 k_strings.cpp -o k_strings_prog
$ ./k_strings_prog
abc
The initial value does double duty in these calls: it seeds the combination and it sets the result type. std::reduce(v.begin(), v.end(), std::string("")) accumulates into a std::string; the same range reduced with an initial 0 would try to add strings to an int and fail to compile. Pick the initial value's type as deliberately as its value.
The execution-policy overloads: a second header, and a library question
Three of the six overloads take an execution policy as the first argument - std::execution::seq, std::execution::par, or std::execution::par_unseq - and those policies live in a second header, <execution>. With both headers included, all three calls compile and run here, each reporting 42:
#include <execution>
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << std::reduce(std::execution::seq, v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 p_seq.cpp -o p_seq_prog
$ ./p_seq_prog
42
#include <execution>
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << std::reduce(std::execution::par, v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 p_par.cpp -o p_par_prog
$ ./p_par_prog
42
The par_unseq version of the same program - the same file with std::execution::par_unseq in the call - also compiles and runs, reporting 42. Two things about these transcripts are specific to this machine and worth stating plainly. First, no -ltbb appears on any command line: on this machine the parallel-policy call compiles, links, and runs without naming that library. Second, adding it breaks the build, because the library is not installed here:
$ g++ -std=c++20 p_par_tbb.cpp -o p_par_tbb_prog -ltbb
/usr/bin/ld: cannot find -ltbb: No such file or directory
collect2: error: ld returned 1 exit status
So whether a policy call needs an extra library on the link line is a property of the machine and the library version, not of the call - check it where the program will actually build, and do not copy a -ltbb from a tutorial onto a machine that has no such library, or drop one a different machine needs.
The policy call also fails differently when only one of its two headers is present. With <numeric> included but <execution> missing, the error is not about reduce at all - the policy name itself is undeclared:
#include <numeric>
int main() {
int a[4] = {10, 20, 5, 7};
return std::reduce(std::execution::seq, a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 p_policy_noexec.cpp -o p_policy_noexec_prog
p_policy_noexec.cpp: In function 'int main()':
p_policy_noexec.cpp:4:29: error: 'std::execution' has not been declared
4 | return std::reduce(std::execution::seq, a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~~~~
And with <execution> included but <numeric> missing, the same policy call compiles and runs, returning success - <execution> is one of the two transitive rescues in the sweep, and it rescues the policy overloads along with the plain ones:
#include <execution>
int main() {
int a[4] = {10, 20, 5, 7};
return std::reduce(std::execution::seq, a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 p_policy_nonumeric.cpp -o p_policy_nonumeric_prog
$ ./p_policy_nonumeric_prog
That rescue is still not a rule: a file that names both std::reduce and a policy includes both <numeric> and <execution>, so the call does not depend on one header happening to pull in the other.
Versions: C++17 to call it, C++20 to constant-fold it, and no note either way
The call itself needs C++17: the plain program in the sweep shape compiles and runs under -std=c++17 with <numeric> included. A static_assert over the call is a different matter. The non-policy overloads are constexpr only since C++20, so this program compiles under C++20:
#include <array>
#include <numeric>
int main() {
constexpr std::array<int, 4> a = {10, 20, 5, 7};
static_assert(std::reduce(a.begin(), a.end(), 0) == 42);
return 0;
}
$ g++ -std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog
Under C++17 the same program fails - not with a missing-name error, because the name is there, but with a call to a non-constexpr function:
$ g++ -std=c++17 c_constexpr20_as17.cpp -o c_constexpr20_as17_prog
c_constexpr20_as17.cpp: In function 'int main()':
c_constexpr20_as17.cpp:5:54: error: non-constant condition for static assertion
5 | static_assert(std::reduce(a.begin(), a.end(), 0) == 42);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
c_constexpr20_as17.cpp:5:30: error: call to non-'constexpr' function '_Tp std::reduce(_InputIterator, _InputIterator, _Tp) [with _InputIterator = const int*; _Tp = int]'
5 | static_assert(std::reduce(a.begin(), a.end(), 0) == 42);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from c_constexpr20_as17.cpp:2:
/usr/include/c++/13/numeric:325:5: note: '_Tp std::reduce(_InputIterator, _InputIterator, _Tp) [with _InputIterator = const int*; _Tp = int]' declared here
325 | reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
| ^~~~~~
Under C++14 the name is not there at all, even with <numeric> included - and here this error's silence costs the most, because the output is identical to the missing-include case: the same plain error, and no version note to separate a too-old standard from a missing header:
$ g++ -std=c++14 c_reduce14.cpp -o c_reduce14_prog
c_reduce14.cpp: In function 'int main()':
c_reduce14.cpp:4:17: error: 'reduce' is not a member of 'std'
4 | return std::reduce(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~
Its sibling std::invoke gets a note naming the standard in exactly this situation; std::reduce does not. When the include is already in the file and the error persists, the standard flag is the next thing to check - the diagnostic will not tell you.
The neighboring names: the whole family shares the one header
The names std::reduce is used alongside do not split by home header the way other families do - every one of them lives in <numeric> too. std::accumulate - the older left fold this call relaxes - fails in the lean context here, only <limits> included, with its own plain error and the same absence of a note. It is shown here only as a neighbor, not re-taught:
#include <limits>
int main() {
int a[4] = {10, 20, 5, 7};
return std::accumulate(a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 b_accumulate_lean.cpp -o b_accumulate_lean_prog
b_accumulate_lean.cpp: In function 'int main()':
b_accumulate_lean.cpp:4:17: error: 'accumulate' is not a member of 'std'
4 | return std::accumulate(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~~~~~
std::transform_reduce - the C++17 sibling that maps a unary operation over the range and then reduces - fails the same way in the same lean context:
#include <limits>
int main() {
int a[4] = {1, 2, 3, 4};
return std::transform_reduce(a, a + 4, 0, [](int x, int y) { return x + y; },
[](int x) { return x * x; }) == 30 ? 0 : 1;
}
$ g++ -std=c++20 b_transform_reduce_lean.cpp -o b_transform_reduce_lean_prog
b_transform_reduce_lean.cpp: In function 'int main()':
b_transform_reduce_lean.cpp:4:17: error: 'transform_reduce' is not a member of 'std'
4 | return std::transform_reduce(a, a + 4, 0, [](int x, int y) { return x + y; },
| ^~~~~~~~~~~~~~~~
std::inner_product and std::iota - the pairwise combine-and-accumulate and the filling counter, both in <numeric> since long before std::reduce existed - fail the same way, each with its own name in the same plain sentence:
#include <limits>
int main() {
int a[3] = {1, 2, 3};
int b[3] = {4, 5, 6};
return std::inner_product(a, a + 3, b, 0) == 32 ? 0 : 1;
}
$ g++ -std=c++20 b_inner_product_lean.cpp -o b_inner_product_lean_prog
b_inner_product_lean.cpp: In function 'int main()':
b_inner_product_lean.cpp:5:17: error: 'inner_product' is not a member of 'std'
5 | return std::inner_product(a, a + 3, b, 0) == 32 ? 0 : 1;
| ^~~~~~~~~~~~~
#include <limits>
int main() {
int a[3] = {0, 0, 0};
std::iota(a, a + 3, 10);
return a[0] + a[1] + a[2] == 33 ? 0 : 1;
}
$ g++ -std=c++20 b_iota_lean.cpp -o b_iota_lean_prog
b_iota_lean.cpp: In function 'int main()':
b_iota_lean.cpp:4:10: error: 'iota' is not a member of 'std'
4 | std::iota(a, a + 3, 10);
| ^~~~
The neighboring names, fixed
Each neighboring name works under the same one added header - there is no second header to reach for in this family. std::accumulate works under <numeric> alone, with no other include in the file: the lean program with <limits> swapped for <numeric> compiles and runs, returning success. And the fixed std::transform_reduce program reports 30 - the squares of 1, 2, 3, and 4, summed:
#include <iostream>
#include <numeric>
int main() {
int a[4] = {1, 2, 3, 4};
std::cout << std::transform_reduce(a, a + 4, 0, [](int x, int y) { return x + y; },
[](int x) { return x * x; }) << "\n";
return 0;
}
$ g++ -std=c++20 b_transform_reduce_fixed.cpp -o b_transform_reduce_fixed_prog
$ ./b_transform_reduce_fixed_prog
30
One header, <numeric>, covers the whole conversation: reduce, accumulate, transform_reduce, inner_product, and iota all take it, and a file that uses any of them and lacks it gets the same plain error with the name swapped.
A different wording - and two cases where the qualifier is not needed, and one where it is
Including <numeric> is not the only half of the name. This program includes the header, drops the std:: qualifier, and passes raw pointers - a pointer belongs to no namespace, so no lookup finds the name:
#include <numeric>
int main() {
int a[4] = {10, 20, 5, 7};
return reduce(a, a + 4, 0) == 42 ? 0 : 1;
}
$ g++ -std=c++20 g_unqualified_ptr.cpp -o g_unqualified_ptr_prog
g_unqualified_ptr.cpp: In function 'int main()':
g_unqualified_ptr.cpp:4:12: error: 'reduce' was not declared in this scope; did you mean 'std::reduce'?
4 | return reduce(a, a + 4, 0) == 42 ? 0 : 1;
| ^~~~~~
| std::reduce
In file included from /usr/include/c++/13/numeric:739,
from g_unqualified_ptr.cpp:1:
/usr/include/c++/13/pstl/glue_numeric_defs.h:31:1: note: 'std::reduce' declared here
31 | reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
| ^~~~~~
That wording - was not declared in this scope, with did you mean 'std::reduce'? 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::reduce; adding includes does not bring the name out of namespace std.
The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 42:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << reduce(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified_vec.cpp -o g_unqualified_vec_prog
$ ./g_unqualified_vec_prog
42
And the unqualified call with an execution policy as its first argument also compiles and runs, printing 42:
#include <execution>
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {10, 20, 5, 7};
std::cout << reduce(std::execution::seq, v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified_policy.cpp -o g_unqualified_policy_prog
$ ./g_unqualified_policy_prog
42
What happened: the iterators and the policy object belong to namespace std, so argument-dependent lookup finds std::reduce from the arguments themselves, even without the qualifier. That is a property of the argument types, not a style to rely on: the same call over raw pointers fails, as the transcript above shows. Write the qualifier either way.
The exact rule
std::reduceis declared by#include <numeric>, and by no other header by rule. In the sweep probed here, every one of the other 103 headers in the library's header set - among them<algorithm>,<iostream>,<vector>,<string>,<utility>, and<version>- does not declare it, and neither does a file with no include at all.'reduce' is not a member of 'std'means the<numeric>include is missing and nothing else in the file pulled the name in - or, under a standard before C++17, that the name does not exist yet in that standard. In every context probed here, GCC prints no suggestion tail on the error line, no note lines, and no help lines for this name - the missing-include case and the too-old-standard case print identically, and only the file's own include list and standard flag separate them.- In the sweep probed here, the split is two-way: a sole header either fails with that one uniform bare shape, or rescues the program. No probed sole header produces a note class, a suggestion class, or a declared-but-not-defined link-failure shape for this name - the contrast with
std::invoke, whose failing headers all carry a note naming<functional>. - In the sweep probed here, only two headers besides
<numeric>rescuestd::reducetransitively -<execution>and<random>- so a file whose only include is one of those compiles and runs the call without<numeric>. That is this library version's behavior, not a guarantee - in the probed set, neither header is required to pullstd::reducein. - The call combines the range in an unspecified order: the fixed programs here print
42 42 7000for the no-init sum, the init sum, and the multiplication with init 1 over 10, 20, 5, and 7, and the order program prints-116 -86forstd::accumulateandstd::reducerunning the same subtraction - the fold is ordered, the reduction is not, and an operation that is not associative and commutative can give different results under the two. - The initial value sets the result type as well as the starting point: the string program prints
abcbecause its initial value is astd::string, and the same range with anintinitial value would not compile. - The execution-policy overloads take two headers:
<numeric>for the name and<execution>for the policy. With<numeric>alone the policy call fails with'std::execution' has not been declared; with both, theseq,par, andpar_unseqcalls each print42here, with no extra library on the link line - and-ltbbon this machine fails the link withcannot find -ltbb, because that library is not installed here. std::reduceis a C++17 function template; its non-policy overloads areconstexprsince C++20: astatic_assertover the call compiles under C++20 and fails under C++17 with a call to a non-constexprfunction, and under C++14 the name itself is absent with the same plain error and no note.std::accumulate,std::transform_reduce,std::inner_product, andstd::iotaare declared by the same#include <numeric>: in the lean programs here, which include only<limits>, each gets its ownis not a member of 'std'error, each with no note - one header fixes all five names.'reduce' was not declared in this scopefor an unqualifiedreduceuse over raw pointers is a different defect: qualify the name asstd::reduce- the include alone does not bring the name out of namespacestd. The same unqualified use overstd::vectoriterators, or with astd::execution::seqpolicy argument, compiles in the programs probed here through argument-dependent lookup; qualify the name there too, so the call does not depend on its argument types.
The fixes, ranked
- First, check the include list of the file that names
std::reduce. If<numeric>is not there, add it - that is the fix in the common case, and it holds whether the file failed in a lean context, failed in a textbook file, or happened to compile before through a transitive rescue. - Second, do not wait for a note to confirm the header - for this error there is none. In the contexts probed here the diagnostic is one bare line; take the fix from the name's home header,
<numeric>, not from the output. - Third, do not reach for
<algorithm>because the call reads like an algorithm. In the sweep probed here,<algorithm>as the only include fails forstd::reducewith the same error - the numeric algorithms live in<numeric>, alongsidestd::accumulate. - Fourth, if the failing call takes an execution policy, check for
<execution>as well as<numeric>: the policy name has its own header, and its absence fails with'std::execution' has not been declared, a different sentence pointing at the second include. - Fifth, do not be reassured by
<iostream>,<vector>, or<string>being present - in the sweep here none of them rescues this name at all - and do not remove<numeric>because a file compiles without it: in the probed set only<execution>and<random>rescue it, and those rescues are not guaranteed. Do not copy a link-line library flag from a tutorial either: on this machine-ltbbbreaks a policy build that works without it. - Sixth, check the standard before changing the code when the include is already right. Under C++14 this name does not exist, and under C++17 it exists but is not
constexpr, so astatic_assertover the call needs C++20. The diagnostic will not separate these cases - both can print the same plain error or a non-constexprcomplaint - so read the build's standard flag directly. - Seventh, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::reduceas well - and do not rely on an unqualified call that happens to compile overstditerators or astdpolicy object, because the same call over raw pointers fails. - Eighth, if the failing name is a neighboring one, the fix is the same header:
accumulate,transform_reduce,inner_product, andiotaall take the same added<numeric>- one include for the whole family.
Which fix for which cause
#include <numeric>missing,std::reduceused in a file whose only include is one of the 103 headers listed as failing in the sweep section above, or that includes nothing: the message is'reduce' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add#include <numeric>.std::reduceused in a textbook file including<iostream>and<vector>: the message is the same bare error - add#include <numeric>.std::reduceused with only<numeric>,<execution>, or<random>included: no error on this library version - add#include <numeric>anyway when it is not the include already present, because the<execution>and<random>rescues are not guaranteed.std::reducecalled with an execution policy,<numeric>included but<execution>missing: the message is'std::execution' has not been declared- add#include <execution>. With<execution>alone the call compiles on this library version - add<numeric>anyway.- A policy build failing at link time with
cannot find -ltbbafter a tutorial's flag was copied onto the command line: the library is not installed on that machine and the call did not need it there - remove the flag, or install the library the build actually requires; on this machine the same call links and runs with no flag. std::reduceused in astatic_assertwith<numeric>included under C++17: the message is a call to a non-constexprfunction - compile as C++20 or later, where the non-policy overloads areconstexpr. Under C++14 the message is'reduce' is not a member of 'std'with no note - compile as C++17 or later for the call itself.std::accumulate,std::transform_reduce,std::inner_product, orstd::iotaused without<numeric>in the lean context: the message names that name, with no note - add#include <numeric>.reduceused without thestd::qualifier,<numeric>included, over raw pointers: the message is'reduce' was not declared in this scope; did you mean 'std::reduce'?- qualify the name asstd::reduce. Withstd::vectoriterators or astd::executionpolicy as arguments the same unqualified call compiles through argument-dependent lookup in the programs probed here - qualify it anyway.
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 the absence of a note as a different error. For this name the missing-include diagnostic is one bare line in every probed context; the note that names the home header for
std::invokehas no counterpart here. - Do not import a neighboring family's split into this error: in this family every name -
reduce,accumulate,transform_reduce,inner_product,iota- takes the same<numeric>, so there is no per-name header to look up. - Do not assume the textbook includes rescue this name, and do not delete a working
<numeric>line because a file compiles without it. In the sweep here<iostream>and<vector>do not rescuestd::reduceat all, and the two headers that do rescue it do so only transitively. - Match the standard and the headers to the use: the call itself needs C++17 and
<numeric>, a constant-expression call needs C++20, and a policy call needs<execution>on top of<numeric>. - Check the operation before trusting the result:
std::reducemay combine in any order, so an operation that is not associative and commutative - subtraction, division, floating-point addition - can give a different result fromstd::accumulateover the same range, as the-116 -86program shows. - One header per name the file uses:
std::vectorcomes from<vector>andstd::stringcomes from<string>, even in a program whose subject is the reduction - andstd::reducecomes from<numeric>in return. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
42 42 7000for the three plain overloads, and42for each of the three execution-policy calls.
Related guides
- 'std::invoke' Is Not a Member of 'std' Fix - the same missing-include shape for the uniform call wrapper in
<functional>: its sweep is just as uniform, but every failing header there carries a note naming the home header, where this guide's failing headers carry no note at all, and its rescue set is one header where this guide's is two. - 'std::min_element' Is Not a Member of 'std' Fix - the same missing-include shape for the smallest-element search in
<algorithm>: its sweep splits between a plain class and a wrong-name suggestion class where this guide's sweep is uniform and bare, and its rescue set is five headers where this guide's is two.
Sources
- cppreference,
std::reduce— forstd::reducebeing a function template defined in<numeric>since C++17 whose non-policy overloads areconstexprsince C++20, that reduces the range possibly permuted and aggregated in an unspecified manner, that behaves likestd::accumulateexcept the elements may be grouped and rearranged in arbitrary order - with a non-deterministic result when the operation is not associative or not commutative - whose policy overloads execute according to the given execution policy and participate in overload resolution only when the policy type satisfies the execution-policy test, and whose parallel-algorithm feature-test macro is__cpp_lib_parallel_algorithm(201603L, C++17). - cppreference, Standard library header
<numeric>— for<numeric>being the header that declaresstd::reduceand its execution-policy overloads alongsidestd::accumulate,std::inner_product,std::transform_reduce,std::partial_sum, the scan family, andstd::adjacent_difference. - cppreference,
std::accumulate— forstd::accumulatebeing a function template defined in<numeric>that folds a range strictly from the left, the ordered counterpart the order program comparesstd::reduceagainst. - cppreference,
std::transform_reduce— forstd::transform_reducebeing a function template defined in<numeric>since C++17 that applies a unary operation to the range's elements and reduces the results.
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.