Is this the only solution when there is a pointer that points to a vector and we would like to use accumulate to sum up numbers? Is there any simpler solution rather than writing a lambda function and using a four argument type of accumulating?
Also, for using std::sort
, will the situation be the same?
Here is the code:
#include <random>
#include <vector>
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
const int N=3;
auto p=make_unique<array<int,N>> ();
(*p)[0]=3;
(*p)[1]=4;
(*p)[2]=5;
sum=accumulate(p,?,0);
return 0;
}