partial_sum

include

include

using namespace std;

int main() {
int val[] = {1,2,3,4,5};
int result[5];

partial_sum (val, val+5, result);
cout << “using default partial_sum: “;
for (int i=0; i<5; i++)
cout << result[i] << ’ ‘;
cout << endl;

partial_sum (val, val+5, result, multiplies());
cout << “using functional operation multiplies: “;
for (int i=0; i<5; i++)
cout << result[i] << ’ ‘;
cout << endl;

partial_sum (val, val+5, result, [](int x,int y){return x + y + 1;});
cout << “using custom function: “;
for (int i=0; i<5; i++)
cout << result[i] << ’ ‘;
cout << endl;
return 0;
}

运行结果

using default partial_sum: 1 3 6 10 15
using functional operation multiplies: 1 2 6 24 120
using custom function: 1 4 8 13 19

你可能感兴趣的:(partial_sum)