std::accumulate
has a small trap, which is the initial value that you pass. It can be easily overlooked that this value is used to display a parameter T
that is also a return type (and the return type is not , namely the value_type
container). Correct it by passing long long
as the initial value:
sum = accumulate(v.begin(),v.end(),(long long)0);
or for paranoids (sorry, just jokes with raw castes are really not good):
sum = accumulate(v.begin(),v.end(),0LL);
source
share