Logo

Programming-Idioms

History of Idiom 54 > diff from v44 to v45

Edit summary for version 45 by WHS:
[C++] minor correction to comment

Version 44

2020-12-24, 16:45:36

Version 45

2020-12-24, 16:46:14

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Variables
s,x
Variables
s,x
Imports
#include <functional>
#include <numeric>
Imports
#include <functional>
#include <numeric>
Code
int s = std::accumulate(x.begin(), x.end(), 0, std::plus<int>());
Code
int s = std::accumulate(x.begin(), x.end(), 0, std::plus<int>());
Comments bubble
std::plus<>() parameter optional
Comments bubble
std::plus<int>() parameter optional (defaults to this if not provided)