Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
initial = 0;
total = fold(std::begin(xs), std::begin(xs) + 5, initial, [](int acc, int x) { return acc + x; });
std::cout << total << "\n"; //15
initial = 1;
total = fold(std::begin(xs), std::begin(xs) + 4, initial, [](int acc, int x) { return acc * x; });
std::cout << total << "\n"; //24
initial = 0;
total = std::accumulate(std::begin(xs), std::end(xs), initial, std::plus<int>());
std::cout << total << "\n"; //55
initial = 1;
total = std::accumulate(std::begin(xs), std::begin(xs) + 4, initial, [](int acc, int x) { return acc * x; });
std::cout << total << "\n"; //24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment