forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice_examples.cpp
More file actions
58 lines (47 loc) · 1.33 KB
/
slice_examples.cpp
File metadata and controls
58 lines (47 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <slice.hpp>
#include <range.hpp>
#include <vector>
#include <array>
int main() {
std::string a = "hello world";
std::cout << "a = { ";
for (auto&& i : a) {
std::cout << i << ' ';
}
std::cout << "}\n";
// just like range(), the step doesn't have to make it end anywhere
// specific, below, the step is too great to cover more than two elements
std::cout << "slice(a, 1, 4, 7): { ";
for (auto&& i : iter::slice(a, 1, 4, 5)) {
std::cout << i << ' ';
}
std::cout << "\n";
std::cout << "slice(a, 2): { ";
for (auto&& i : iter::slice(a, 2)) {
std::cout << i << ' ';
}
std::cout << "}\n";
std::cout << "slice(a, 1, 5): { ";
for (auto&& i : iter::slice(a, 1, 5)) {
std::cout << i << ' ';
}
std::cout << "}\n";
std::cout << "slice(a, 2, 8, 2): { ";
for (auto&& i : iter::slice(a, 2, 8, 2)) {
std::cout << i << ' ';
}
std::cout << "}\n";
// the stop can be beyond the end
std::cout << "slice(a, 100): { ";
for (auto&& i : iter::slice(a, 100)) {
std::cout << i << ' ';
}
std::cout << "}\n";
// the start can too
std::cout << "slice(a, 100, 200): { ";
for (auto&& i : iter::slice(a, 100, 200)) {
std::cout << i << ' ';
}
std::cout << "}\n";
}