forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccumulate_examples.cpp
More file actions
22 lines (19 loc) · 596 Bytes
/
Copy pathaccumulate_examples.cpp
File metadata and controls
22 lines (19 loc) · 596 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <accumulate.hpp>
#include <range.hpp>
#include <iostream>
#include <vector>
int main() {
std::vector<int> vec = {0, 1, 2, 3, 4, 5};
// accumulate adds elements by default
std::cout << "accumulate({1, 2, 3, 4, 5}): { ";
for (auto i : iter::accumulate(vec)) {
std::cout << i << ' ';
}
std::cout << "}\n";
// accumulate with a lambda for subtraction
std::cout << "accumulate({1, 2, 3, 4, 5}, subtract): { ";
for (auto i : iter::accumulate(vec, [](int a, int b){return a - b;})) {
std::cout << i << ' ';
}
std::cout << "}\n";
}