C++
'std::partial_sum' Is Not a Member of 'std' Fix
std::partial_sum lives in one header, <numeric> - not in <algorithm>, where most algorithm names live, and not in <vector>, where the containers it reads and writes live. On this library version two headers rescue it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, <execution> and <random> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. Four headers do something worse than failing plainly: <algorithm>, <functional>, <regex>, and <valarray> fail with a suggestion to use std::partial_sort, a different function that sorts part of a range. This name has no second cause hiding behind the first: it predates C++11, so a file compiled as C++98 with the include present sums correctly - the include is the only thing that can be wrong. This guide pins down the plain failing shape, the misleading suggestion shape, the two transitive rescues, and the one include that fixes it.
Written December 2, 2026 · Tested with GCC 13.3.0 · 29 min read
- The error: the include is missing, in a lean file
- The textbook version fails too - plainly
- Neighboring headers: 99 fail plainly, four fail with the partialsort suggestion, and two rescue it
- The fix
Written December 2, 2026
Tested with GCC 13.3.0
What this guide is
std::partial_sum is a function template defined in the header <numeric>. It computes the partial sums - the running totals - of a source range and writes them to a destination range: the first output is the first element, the second is the sum of the first two, and so on, and it returns the past-the-end iterator of the destination range. The source iterators need only meet the input-iterator requirements and the destination iterator the output-iterator requirements, and for a range of N elements the addition - or the caller's binary operation, in the second overload - is applied exactly N - 1 times. The destination may begin at the source's own first iterator, so the call can run in place. Both overloads predate C++11 and have no standard floor of their own.
Because the function lives in one specific header - and not in <algorithm>, the header its name and shape suggest - 'partial_sum' is not a member of 'std' has one cause, and naming it is the first step:
- 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 the bare error line for most headers - and for four headers, among them<algorithm>itself, it adds a suggestion tail namingpartial_sort, a different function, as the sweep below shows.
There is no version form of this failure. std::partial_sum is an original name, older than C++11, so a file that includes <numeric> and is compiled as C++98 sums correctly, as the versions section below shows. Its newer neighbors in this header do have that second cause; this name does not, and a reader who raises the standard flag to chase this error is fixing a flag that was never the problem.
A running-total program's file most often already holds <vector> for the containers and <iostream> for printing, and in the sweep probed here both fail plainly - so the file a reader actually has gets the bare version of the error, with nothing in the diagnostic pointing anywhere. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits three ways - the plain failure, the suggestion failure, or a rescue - and the rescue set has exactly three entries: <numeric> itself, <execution>, and <random>.
The error: the include is missing, in a lean file
This program writes the running totals of a five-element array into a second array, but includes only <limits>:
#include <limits>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
auto e = std::partial_sum(a, a + 5, out);
return e == out + 5 && out[4] == 15 ? 0 : 1;
}
-std=c++17 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:5:19: error: 'partial_sum' is not a member of 'std'
5 | auto e = std::partial_sum(a, a + 5, out);
| ^~~~~~~~~~~
That is the whole output: one plain error line, and nothing after it. No suggestion tail rides on the error line itself, there are no note lines, and there are no help lines. The same program with no include at all fails the same way, just as bare, at the same call.
The textbook version fails too - plainly
The version most often written first - write the running totals of a vector and print them - gets the same error, without <numeric>, and in this combination the error line carries no tail:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<int> out(v.size());
std::partial_sum(v.begin(), v.end(), out.begin());
for (std::size_t i = 0; i < out.size(); ++i) {
if (i) std::cout << " ";
std::cout << out[i];
}
std::cout << "\n";
return 0;
}
-std=c++17 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:6:10: error: 'partial_sum' is not a member of 'std'
6 | std::partial_sum(v.begin(), v.end(), out.begin());
| ^~~~~~~~~~~
Nothing follows the caret line: no suggested name, no marker line under the caret, no notes. The fix here is the header this call actually takes: the running totals take <numeric>, and neither <iostream> nor <vector> rescues it - in the sweep probed here, the only headers that rescue std::partial_sum 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::partial_sum includes <numeric>, whether or not it happens to compile without it.
The trap: the one suggestion points at the wrong function
std::partial_sum looks like an algorithm, so the file gets <algorithm> - and on this library version that file still fails, but now the error line carries a tail suggesting a different name:#include <algorithm>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
auto e = std::partial_sum(a, a + 5, out);
return e == out + 5 && out[4] == 15 ? 0 : 1;
}
-std=c++17 a_algorithm.cpp -o a_algorithm_prog
a_algorithm.cpp: In function 'int main()':
a_algorithm.cpp:5:19: error: 'partial_sum' is not a member of 'std'; did you mean 'partial_sort'?
5 | auto e = std::partial_sum(a, a + 5, out);
| ^~~~~~~~~~~
| partial_sort
Follow that suggestion and the program changes meaning: std::partial_sort sorts the first part of a range - it does not compute running totals, takes a different argument list, and would not compile in this call's place without rewriting the call, and rewriting it would silently replace a sum with a sort. The tail exists because <algorithm> pulls in the declaration neighborhood where partial_sort lives, close enough in spelling for the compiler to offer it; it is a spelling neighbor, not a home for this name. In the sweep below, exactly four sole headers produce this tail - <algorithm>, <functional>, <regex>, and <valarray> - and every one of them is a header that pulls the algorithm internals in on the side. The fix is unchanged by the tail: this name takes <numeric>.
Neighboring headers: 99 fail plainly, four fail with the partial_sort suggestion, 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 writes the running totals of a five-element array into a second array and checks them against 1, 3, 6, 10, 15, the outcome splits by compile result and diagnostic shape three ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 99 headers all fail with the plain is not a member of 'std' error line, no suggestion tail on that line, no note lines at all, and no help lines:
<any><array><atomic><barrier><bit><bitset><cassert><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><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><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 plainly the same way.
Four headers fail with a suggestion tail - the error line reads 'partial_sum' is not a member of 'std'; did you mean 'partial_sort'?, a marker line under the caret repeats the suggested name, and there are still no note lines and no help lines:
<algorithm><functional><regex><valarray>
A sole <vector> file shows the plain shape in full - and <vector> is one of the headers this call is most often expected in, since the containers being summed over and written to come from it. It is not there:
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4};
std::vector<int> out(v.size());
auto e = std::partial_sum(v.begin(), v.end(), out.begin());
return e == out.end() && out[3] == 10 ? 0 : 1;
}
-std=c++17 v_vector.cpp -o v_vector_prog
v_vector.cpp: In function 'int main()':
v_vector.cpp:5:19: error: 'partial_sum' is not a member of 'std'
5 | auto e = std::partial_sum(v.begin(), v.end(), out.begin());
| ^~~~~~~~~~~
And these headers rescue the program - it compiles and runs with no <numeric> anywhere in the file:
<numeric><execution><random>
Two contrasts with the neighboring sweeps are worth holding on to. First, the suggestion class for this name is a trap rather than a guide: the four headers that produce it are exactly the headers that pull the algorithm header's internals in, and the name they suggest, partial_sort, belongs to that header - the suggestion reports what the included header happens to declare nearby, not where partial_sum lives. Second, the rescue set is smaller than its neighbors' and has no visible container or iterator shape: one execution header and <random> - headers that pull the numeric header's internals in on the side, which is consistent with a name whose home is the numeric header, not the algorithm header its shape suggests. <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 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<int> out(v.size());
std::partial_sum(v.begin(), v.end(), out.begin());
for (std::size_t i = 0; i < out.size(); ++i) {
if (i) std::cout << " ";
std::cout << out[i];
}
std::cout << "\n";
return 0;
}
-std=c++17 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
1 3 6 10 15 21 28 36 45 55
One include, <numeric>, declares the function - and the output reports 1 3 6 10 15 21 28 36 45 55: each entry is the sum of the population 1 through 10 up to that position, so the last entry is the total of the whole range. The values land in the destination range; the call's own return value is the iterator just past the last value written, as the next section shows.
The return value is the destination's past-the-end iterator - and the destination may be the source
The call returns where writing stopped. Over 1, 2, 3, 4 written to a separate array, the return is 4 past the destination's start - one past the last total written. And because the destination is allowed to be the source itself, the same call run in place over the same values produces the same totals in the source array and returns the same offset:
#include <iostream>
#include <numeric>
int main() {
int a[4] = {1, 2, 3, 4};
int out[4] = {0, 0, 0, 0};
auto e = std::partial_sum(a, a + 4, out);
for (int i = 0; i < 4; ++i) {
if (i) std::cout << " ";
std::cout << out[i];
}
std::cout << " end " << (e - out) << "\n";
int b[4] = {1, 2, 3, 4};
auto e2 = std::partial_sum(b, b + 4, b);
for (int i = 0; i < 4; ++i) {
if (i) std::cout << " ";
std::cout << b[i];
}
std::cout << " end " << (e2 - b) << "\n";
return 0;
}
-std=c++17 r_return.cpp -o r_return_prog
$ ./r_return_prog
1 3 6 10 end 4
1 3 6 10 end 4
Read in order: the separate-destination call writes 1 3 6 10 and reports end 4 - the offset of the returned iterator from the destination's start, equal to the number of elements written. The in-place call then overwrites 1, 2, 3, 4 with 1 3 6 10 in the source array itself and reports end 4 again. Code that needs to know how much was written compares that returned iterator against the destination's start; code that only needs the totals reads the destination range and ignores the return.
The edge ranges: empty and one element
No short range is an error. An empty range writes nothing - the destination keeps whatever it already held - and returns the destination's start, and a one-element range writes that element unchanged, because there is nothing to add to it yet:
#include <iostream>
#include <numeric>
int main() {
int a[1] = {8};
int out[1] = {99};
auto e1 = std::partial_sum(a, a, out);
std::cout << "empty " << (e1 - out) << " " << out[0] << "\n";
int out2[1] = {0};
auto e2 = std::partial_sum(a, a + 1, out2);
std::cout << "one " << (e2 - out2) << " " << out2[0] << "\n";
return 0;
}
-std=c++17 k_empty.cpp -o k_empty_prog
$ ./k_empty_prog
empty 0 99
one 1 8
The empty call reports offset 0 and the sentinel 99 placed in the destination beforehand is still there - no write happened. The one-element call reports offset 1 and writes 8, the element itself: with N elements the operation is applied exactly N - 1 times, so a one-element range applies it zero times and an empty range has no first element to copy.
The binary-operation overload: products and a custom operation
The second overload replaces the addition with any binary operation. With std::multiplies the running totals become running products, and with a free function the operation can be anything - here one that adds the two values and one more:
#include <functional>
#include <iostream>
#include <numeric>
int addOne(int x, int y) { return x + y + 1; }
int main() {
int a[5] = {1, 2, 3, 4, 5};
int prod[5] = {0, 0, 0, 0, 0};
std::partial_sum(a, a + 5, prod, std::multiplies<int>());
for (int i = 0; i < 5; ++i) {
if (i) std::cout << " ";
std::cout << prod[i];
}
std::cout << "\n";
int b[4] = {1, 2, 3, 4};
int custom[4] = {0, 0, 0, 0};
std::partial_sum(b, b + 4, custom, addOne);
for (int i = 0; i < 4; ++i) {
if (i) std::cout << " ";
std::cout << custom[i];
}
std::cout << "\n";
return 0;
}
-std=c++17 o_op.cpp -o o_op_prog
$ ./o_op_prog
1 2 6 24 120
1 4 8 13
The product line reads 1 2 6 24 120: 1, then 1 times 2, then 2 times 3, then 6 times 4, then 24 times 5. The custom line reads 1 4 8 13: the first value is copied, then each step applies the function to the running value and the next element - 1, then 1 + 2 + 1, then 4 + 3 + 1, then 8 + 4 + 1. In both lines the operation runs exactly N - 1 times for N elements - the first element is never passed through it - and the operation must not modify the source or destination ranges or invalidate their iterators.
Input iterators: the totals run on a stream
The iterator requirements are the weakest in this family on both sides: the source needs only input iterators and the destination only an output iterator, so neither side needs to be a container at all. This program reads the source values from a stream of integers one at a time - a range that cannot be rewound and cannot be indexed - and writes the totals out through a back inserter:
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <vector>
int main() {
std::istringstream in("1 2 3 4");
std::istream_iterator<int> first(in), last;
std::vector<int> out;
std::partial_sum(first, last, std::back_inserter(out));
for (std::size_t i = 0; i < out.size(); ++i) {
if (i) std::cout << " ";
std::cout << out[i];
}
std::cout << "\n";
return 0;
}
-std=c++17 i_stream.cpp -o i_stream_prog
$ ./i_stream_prog
1 3 6 10
That is a range shape the forward-iterator algorithms in this family cannot run over at all: a stream iterator can be read once, in order, and std::partial_sum is specified to need nothing more on the source side - one pass, in order, holding only the running value.
Versions: this name has no second cause - it predates C++11
Unlike its newer neighbors, this call does not need a modern standard. The fixed programs in this guide are compiled as C++17, but the classic call has no version floor at all: with <numeric> included, the same call compiled as C++98 compiles and runs, and compiled as C++11 it reports the same totals:
#include <iostream>
#include <numeric>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
std::partial_sum(a, a + 5, out);
for (int i = 0; i < 5; ++i) {
if (i) std::cout << " ";
std::cout << out[i];
}
std::cout << "\n";
return 0;
}
-std=c++98 c_version98.cpp -o c_version98_prog
$ ./c_version98_prog
1 3 6 10 15
-std=c++11 c_version98.cpp -o c_version98_prog
$ ./c_version98_prog
1 3 6 10 15
So this name's error has exactly one cause with exactly one fix, and the diagnostic cannot separate two causes because there is only one: a missing include fails under any standard - plainly under most headers, with the partial_sort suggestion under the four named above - and no standard flag rescues the call when the include is missing, while no file with the include present fails for the standard's reason. There is also no execution-policy overload layered on top of the classic call, and that absence splits in two when a reader tries one anyway. Naming the policy with only <numeric> included fails on the policy's name, not the algorithm's:
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4};
std::vector<int> out(v.size());
auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
return e == out.end() ? 0 : 1;
}
-std=c++17 p_policy_numericonly.cpp -o p_policy_numericonly_prog
p_policy_numericonly.cpp: In function 'int main()':
p_policy_numericonly.cpp:6:36: error: 'std::execution' has not been declared
6 | auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
| ^~~~~~~~~
That wording - has not been declared, naming std::execution - looks like the missing-header shape the policy names in other guides have. Here it is a dead end: add <execution> alongside <numeric>, and the same call still fails, because there is no policy overload of std::partial_sum for the policy to select - the candidates the compiler lists are the two classic overloads, and neither takes a policy as its first argument:
#include <execution>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4};
std::vector<int> out(v.size());
auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
return e == out.end() ? 0 : 1;
}
-std=c++17 p_policy_both.cpp -o p_policy_both_prog
p_policy_both.cpp: In function 'int main()':
p_policy_both.cpp:7:30: error: no matching function for call to 'partial_sum(const __pstl::execution::v1::sequenced_policy&, std::vector<int>::iterator, std::vector<int>::iterator, std::vector<int>::iterator)'
7 | auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/numeric:62,
from /usr/include/c++/13/pstl/parallel_backend_serial.h:16,
from /usr/include/c++/13/pstl/parallel_backend.h:14,
from /usr/include/c++/13/pstl/algorithm_impl.h:22,
from /usr/include/c++/13/pstl/glue_execution_defs.h:50,
from /usr/include/c++/13/execution:34,
from p_policy_both.cpp:1:
/usr/include/c++/13/bits/stl_numeric.h:256:5: note: candidate: 'template<class _InputIterator, class _OutputIterator> _OutputIterator std::partial_sum(_InputIterator, _InputIterator, _OutputIterator)'
256 | partial_sum(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_numeric.h:256:5: note: template argument deduction/substitution failed:
p_policy_both.cpp:7:30: note: deduced conflicting types for parameter '_InputIterator' ('__pstl::execution::v1::sequenced_policy' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
7 | auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_numeric.h:298:5: note: candidate: 'template<class _InputIterator, class _OutputIterator, class _BinaryOperation> _OutputIterator std::partial_sum(_InputIterator, _InputIterator, _OutputIterator, _BinaryOperation)'
298 | partial_sum(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~
/usr/include/c++/13/bits/stl_numeric.h:298:5: note: template argument deduction/substitution failed:
p_policy_both.cpp:7:30: note: deduced conflicting types for parameter '_InputIterator' ('__pstl::execution::v1::sequenced_policy' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
7 | auto e = std::partial_sum(std::execution::seq, v.begin(), v.end(), out.begin());
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The policy forms belong to the neighboring scan names in the same header - std::inclusive_scan and std::exclusive_scan have them; this name does not, at any standard. And since C++20 the classic call is also usable in constant expressions - this program's totals run at compile time, and the assertion on its results is part of the build:
#include <array>
#include <numeric>
constexpr bool check() {
std::array<int, 5> a = {1, 2, 3, 4, 5};
std::array<int, 5> o = {0, 0, 0, 0, 0};
std::partial_sum(a.begin(), a.end(), o.begin());
return o[0] == 1 && o[2] == 6 && o[4] == 15;
}
static_assert(check());
int main() { return 0; }
-std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog
The neighboring name: accumulate is not in either
The sibling this function pairs with does not live in the container's header either. std::accumulate - the single total, which folds a whole range into one value where std::partial_sum writes every intermediate total - lives in <numeric> alongside std::partial_sum, and it fails in a file whose only include is <vector> with its own plain error and no suggestion tail. It is shown here only as a neighbor, not re-taught:
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 4};
auto n = std::accumulate(v.begin(), v.end(), 0);
return n == 14 ? 0 : 1;
}
-std=c++17 b_accum_vector.cpp -o b_accum_vector_prog
b_accum_vector.cpp: In function 'int main()':
b_accum_vector.cpp:4:19: error: 'accumulate' is not a member of 'std'
4 | auto n = std::accumulate(v.begin(), v.end(), 0);
| ^~~~~~~~~~
The neighbors share more than a home: std::accumulate predates C++11 just as std::partial_sum does, so for neither name is a too-old standard a second cause - a C++98 file that includes <numeric> and calls either one gets its result, as the versions section above shows for this guide's name.
The neighboring names, fixed
The two names together take the same one added header - <numeric> covers both, and <vector> covers neither numeric function, only the container they read from. The fixed neighbor program reports 14 for the sum of 1, 2, 3, 4, 4:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 4};
std::cout << std::accumulate(v.begin(), v.end(), 0) << "\n";
return 0;
}
-std=c++17 b_accum_fixed.cpp -o b_accum_fixed_prog
$ ./b_accum_fixed_prog
14
The split is the whole lesson of this family: the numeric functions take <numeric> and the container takes <vector>, the two headers are both needed by a complete running-total program, and a file that has only the container's header gets the not-a-member error for either numeric name - plainly for both, in every include context probed here.
A different wording - and an argument-dependent rescue that depends on every argument
Including <numeric> is not the only half of the name, and for this call the unqualified form splits on all of its arguments - the source iterators, the destination iterator, and the operation alike. Over plain arrays with no operation argument, the unqualified call fails:
#include <numeric>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
auto e = partial_sum(a, a + 5, out);
return e == out + 5 && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:14: error: 'partial_sum' was not declared in this scope; did you mean 'std::partial_sum'?
5 | auto e = partial_sum(a, a + 5, out);
| ^~~~~~~~~~~
| std::partial_sum
In file included from /usr/include/c++/13/numeric:62,
from g_unqualified.cpp:1:
/usr/include/c++/13/bits/stl_numeric.h:298:5: note: 'std::partial_sum' declared here
298 | partial_sum(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~
That wording - was not declared in this scope, with did you mean 'std::partial_sum'? 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::partial_sum; adding includes does not bring the name out of namespace std. (The note happens to point at the binary-operation overload's declaration in the numeric header's internals - both overloads are declared in the same home header's internals; the note's target is a detail of this library's layout, not a second home for the name.) Swapping in a lambda operation over the same plain arrays changes nothing - a lambda's type has no associated namespace either, and the call fails with the same wording:
#include <numeric>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
auto e = partial_sum(a, a + 5, out, [](int x, int y) { return x + y; });
return e == out + 5 && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified_lambda.cpp -o g_unqualified_lambda_prog
g_unqualified_lambda.cpp: In function 'int main()':
g_unqualified_lambda.cpp:5:14: error: 'partial_sum' was not declared in this scope; did you mean 'std::partial_sum'?
5 | auto e = partial_sum(a, a + 5, out, [](int x, int y) { return x + y; });
| ^~~~~~~~~~~
| std::partial_sum
In file included from /usr/include/c++/13/numeric:62,
from g_unqualified_lambda.cpp:1:
/usr/include/c++/13/bits/stl_numeric.h:298:5: note: 'std::partial_sum' declared here
298 | partial_sum(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~
Swap the arrays for a vector on both sides, and the same unqualified call compiles and runs:
#include <numeric>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::vector<int> out(v.size());
auto e = partial_sum(v.begin(), v.end(), out.begin());
return e == out.end() && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified_vec.cpp -o g_unqualified_vec_prog
$ ./g_unqualified_vec_prog
That compile is argument-dependent lookup at work, not a rule to rely on: the vector's iterators are std types, so their associated namespace is std, and lookup finds std::partial_sum through them. But the container being a std type is not enough by itself - over a std::array on both sides, 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 <array>
#include <numeric>
int main() {
std::array<int, 5> a = {1, 2, 3, 4, 5};
std::array<int, 5> out = {0, 0, 0, 0, 0};
auto e = partial_sum(a.begin(), a.end(), out.begin());
return e == out.end() && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified_stdarray.cpp -o g_unqualified_stdarray_prog
g_unqualified_stdarray.cpp: In function 'int main()':
g_unqualified_stdarray.cpp:6:14: error: 'partial_sum' was not declared in this scope; did you mean 'std::partial_sum'?
6 | auto e = partial_sum(a.begin(), a.end(), out.begin());
| ^~~~~~~~~~~
| std::partial_sum
In file included from /usr/include/c++/13/numeric:62,
from g_unqualified_stdarray.cpp:2:
/usr/include/c++/13/bits/stl_numeric.h:298:5: note: 'std::partial_sum' declared here
298 | partial_sum(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~
And the rescue can come from either remaining argument instead of the source. Keep the plain arrays, but make the operation a std type - a std::function wrapping the same addition - and the unqualified call compiles and runs, because the operation argument now has std as an associated namespace:
#include <functional>
#include <numeric>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
std::function<int(int, int)> op = [](int x, int y) { return x + y; };
auto e = partial_sum(a, a + 5, out, op);
return e == out + 5 && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified_stdfunc.cpp -o g_unqualified_stdfunc_prog
$ ./g_unqualified_stdfunc_prog
A library function object does the same on its own: with std::multiplies as the operation over plain arrays, the unqualified call compiles and runs:
#include <functional>
#include <numeric>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int out[5] = {0, 0, 0, 0, 0};
auto e = partial_sum(a, a + 5, out, std::multiplies<int>());
return e == out + 5 && out[4] == 120 ? 0 : 1;
}
-std=c++17 g_unqualified_multiplies.cpp -o g_unqualified_multiplies_prog
$ ./g_unqualified_multiplies_prog
And the destination argument can carry the rescue by itself: keep the source a plain array, but write to a vector's iterator, and the unqualified call compiles and runs - just as, in the probed set, a vector source with a plain-array destination compiles through the source argument:
#include <numeric>
#include <vector>
int main() {
int a[5] = {1, 2, 3, 4, 5};
std::vector<int> out(5);
auto e = partial_sum(a, a + 5, out.begin());
return e == out.end() && out[4] == 15 ? 0 : 1;
}
-std=c++17 g_unqualified_destvec.cpp -o g_unqualified_destvec_prog
$ ./g_unqualified_destvec_prog
Every argument is a possible carrier and none is a guarantee: plain arrays and pointers carry nothing, a lambda operation carries nothing, a vector's iterators carry the name from either side of the call, a std::array's pointer iterators do not, and a std::function or std::multiplies operation carries it on its own. Write the qualifier either way.
The exact rule
std::partial_sumis 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>,<vector>,<iostream>,<string>, and<version>- does not declare it, and neither does a file with no include at all.'partial_sum' is not a member of 'std'has one cause. The missing-include cause: the<numeric>include is missing and nothing else in the file pulled the name in - in the sweep probed here 99 failing sole headers fail with one plain error line, no suggestion tail, no note lines, and no help lines, four failing sole headers -<algorithm>,<functional>,<regex>, and<valarray>- fail with the suggestion taildid you mean 'partial_sort'?and a marker line repeating that name, still with no note lines and no help lines, and no probed sole header produces a note class or a declared-but-not-defined link-failure shape for this name. There is no version cause: with the include present, the call compiles and runs as C++98.- In the sweep probed here, two headers besides
<numeric>rescuestd::partial_sumtransitively -<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, no header besides<numeric>is required to pullstd::partial_sumin. - The result rules are the documented ones, as the fixed programs here show: the fixed program prints
1 3 6 10 15 21 28 36 45 55for the running totals of 1 through 10; over 1, 2, 3, 4 the call writes1 3 6 10and returns an iterator 4 past the destination's start, and the in-place call over the same source writes the same totals and returns the same offset. The returned iterator is compared against the destination's start or end by the caller; the totals themselves are read from the destination range. - The edge ranges are ordinary: an empty range writes nothing and returns the destination's start - the edge program here prints
empty 0 99, the sentinel untouched - and a one-element range writes the element itself and returns an offset of one - the edge program printsone 1 8- because the operation is applied exactly N - 1 times for N elements. - The binary-operation overload replaces the addition with the caller's operation, applied exactly N - 1 times: the operation program here prints
1 2 6 24 120for the running products of 1, 2, 3, 4, 5 understd::multiplies, and1 4 8 13for the custom operation returning x + y + 1 over 1, 2, 3, 4. - The classic
std::partial_sumpredates C++11: with<numeric>included it compiles and runs as C++98 and as C++11, reporting1 3 6 10 15both times for the running totals of 1, 2, 3, 4, 5, and it is usable in constant expressions since C++20. There is no execution-policy overload of this name at any standard: with only<numeric>included, namingstd::execution::seqfails with'std::execution' has not been declared, and with<execution>included alongside it, the policy call fails withno matching function for call to 'partial_sum'. - The source iterators must meet the input-iterator requirements and the destination iterator the output-iterator requirements. The stream program here shows the floor in action: over a stream of integers read one at a time, written out through a back inserter, the totals print
1 3 6 10. std::accumulateis not declared by#include <vector>: in the program here, which includes only<vector>, it gets its ownis not a member of 'std'error, plain, with no suggestion tail - and the fixed neighbor program, which includes both<numeric>and<vector>, prints14for the single-total call.std::accumulatepredates C++11 just asstd::partial_sumdoes, so for that name a standard before C++11 is not a second cause either.'partial_sum' was not declared in this scopefor an unqualifiedpartial_sumuse is a different defect: qualify the name asstd::partial_sum- the include alone does not bring the name out of namespacestd. For this name the unqualified call's fate depends on every argument: over plain arrays with no operation or a lambda operation it fails, as the first two unqualified programs above show; over a vector's iterators it is rescued through argument-dependent lookup, as the third shows, because those iterators arestdtypes; over astd::array's iterators it fails again, because in this library those iterators are plain pointers; an operation argument of astdtype rescues the plain-array call through the operation argument, as thestd::functionandstd::multipliesprograms show; and a vector destination iterator rescues a plain-array source through the destination argument, as the last program shows. Qualify the name either way.
The fixes, ranked
- First, check the include list of the file that names
std::partial_sum. If<numeric>is not there, add it - that is the fix, and it holds whether the file failed in a lean context, in a textbook file, or with thepartial_sortsuggestion, or happened to compile before through a transitive rescue. - Second, do not follow the
partial_sortsuggestion.std::partial_sortsorts part of a range; it does not compute running totals, and the suggestion appears only because the included header -<algorithm>,<functional>,<regex>, or<valarray>- declares that spelling neighbor nearby. The name the error is about takes<numeric>. - Third, do not chase the standard flag for this name: with
<numeric>included, the classic call compiles and runs as C++98, so a too-old standard is not a cause of this error - if the include is present and the error persists, the include is in a different file than the one naming the call, or the name is misspelled. The flag matters only for the piece layered on top: C++20 for constant-expression use. - Fourth, do not reach for
<algorithm>because the call looks like an algorithm, or for<vector>because the call reads and writes containers. In the sweep probed here,<algorithm>fails forstd::partial_sum- with the misleading suggestion - and<vector>fails plainly: the container and the numeric functions live in different headers,std::vectorin<vector>andstd::partial_sumin<numeric>, and a complete program needs both. - Fifth, do not be reassured by
<iostream>being present - in the sweep here it fails too, just as plainly - and do not remove<numeric>because a file compiles without it: in the probed set two headers rescue it, and those rescues are not guaranteed. - Sixth, if the error names
std::executioninstead -'std::execution' has not been declared- do not stop at adding<execution>: there is no execution-policy overload ofstd::partial_sumto select, so the policy argument itself has to go. The classic call, without a policy, is the form this name has; the policy forms belong to the scan names in the same header. - Seventh, match the standard to the one piece beyond the classic call that has a floor: constant-expression use needs C++20.
- Eighth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::partial_sumas well - and do not rely on argument-dependent lookup to rescue the unqualified call, because a plain array, astd::array, and a lambda operation each remove that rescue in one shape or another. - Ninth, if the failing name is the neighboring one, the fix is the same header:
accumulatetakes an added<numeric>too - one header for both numeric names, and<vector>for the container alone.
Which fix for which cause
#include <numeric>missing,std::partial_sumused in a file whose only include is one of the 99 headers listed as failing plainly in the sweep section above, or that includes nothing: the message is'partial_sum' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add#include <numeric>.std::partial_sumused in a file whose only include is<algorithm>,<functional>,<regex>, or<valarray>: the message is'partial_sum' is not a member of 'std'; did you mean 'partial_sort'?- do not follow the suggestion; add#include <numeric>.std::partial_sumused in a textbook file including<iostream>and<vector>: the message is the same plain error, with no tail - add#include <numeric>.std::partial_sumused 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 other two rescues are not guaranteed.std::partial_sumused with<numeric>included, at any standard from C++98 up: no version error - the classic call predates C++11, and the same file reports1 3 6 10 15compiled as C++98 and as C++11.std::partial_sumcalled with an execution policy, with<numeric>included but<execution>not: the message is'std::execution' has not been declared- and with<execution>added, the message becomesno matching function for call to 'partial_sum', because this name has no policy overload: remove the policy argument and call the classic form.partial_sumused without thestd::qualifier,<numeric>included, over array arguments with no operation or a lambda operation, or over astd::array's iterators: the message is'partial_sum' was not declared in this scope; did you mean 'std::partial_sum'?- qualify the name asstd::partial_sum. Over a vector's iterators on either side, or over plain arrays with astd::functionorstd::multipliesoperation, the same unqualified call compiles through argument-dependent lookup - qualify it anyway, so the call does not depend on any argument's type.
Checklist
- Check the include list of the file that names the call, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Do not check the standard flag for the classic call: this is one of the names where the flag is not a cause - C++98 is old enough for it, and only the layered piece has a floor, C++20 for constant-expression use. There is no policy overload to match a standard to.
- Do not import the algorithm header or the container's header into this error:
accumulateandpartial_sumtake<numeric>andstd::vectortakes<vector>, so there are two headers in a complete running-total program, one for the numeric functions and one for the container. - Do not assume the textbook includes rescue this name, do not follow the one suggestion this name produces, and do not delete a working
<numeric>line because a file compiles without it. In the sweep here<iostream>and<vector>do not rescuestd::partial_sumat all,<algorithm>fails with a suggestion to a different function, and the two headers that do rescue it do so only transitively. - Read the return value as a position, not a total: it is the destination's past-the-end iterator, the totals themselves are in the destination range, and an empty range's return - the destination's own start - is an ordinary outcome. The fixed programs here print
1 3 6 10 15 21 28 36 45 55for the ten-element totals andend 4for both the separate and in-place calls over four elements. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
1 3 6 10 15 21 28 36 45 55for the ten-element totals,1 3 6 10withend 4for the return-value cases,1 2 6 24 120and1 4 8 13for the operation cases,1 3 6 10 15for the C++98 and C++11 calls,1 3 6 10for the stream totals, and14for the neighbor single-total call.
Related guides
- 'std::accumulate' Is Not a Member of 'std' Fix - the same missing-include shape for the single-total sibling in the same header:
std::accumulatefolds a range into one value wherestd::partial_sumwrites every intermediate total, the two names share the same home header and the same pre-C++11 age, and neither is declared by the container's header. - 'std::partial_sort' Is Not a Member of 'std' Fix - the name this guide's suggestion tail points at:
std::partial_sortsorts the first part of a range in<algorithm>, a different function with a different job, and following the suggestion instead of adding<numeric>would replace a running total with a partial sort.
Sources
- cppreference,
std::partial_sum— forstd::partial_sumbeing a function template defined in<numeric>; for both overloads carrying no since-version marker of their own, while both are constexpr since C++20, and for there being no execution-policy overload among them; for the destination range being allowed to begin at the source's first iterator; for the return being the past-the-end iterator of the destination range; for the source iterators needing to meet the input-iterator requirements and the destination iterator the output-iterator requirements; for the operation needing to not modify the source or destination ranges or invalidate their iterators; and for the complexity being exactly N - 1 applications of the operation for a range of N elements. - cppreference, Standard library header
<numeric>— for<numeric>being the header whose synopsis declaresstd::accumulateandstd::partial_sum, the home-header fact both the fix and the neighbor sections of this guide rest on.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.