-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
68 lines (62 loc) · 2.62 KB
/
Copy pathTest.cpp
File metadata and controls
68 lines (62 loc) · 2.62 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
59
60
61
62
63
64
65
66
67
//
// main.cpp
// iterable
//
// Created by Jeme Jbareen on 5/12/19.
// Copyright © 2019 Jeme Jbareen. All rights reserved.
//
#include <iostream>
#include <sstream>
#include "range.hpp"
#include "chain.hpp"
#include "zip.hpp"
#include "product.hpp"
#include "powerset.hpp"
using namespace std;
using namespace itertools;
template<typename Iterable>
string iterable_to_string(const Iterable& iterable) {
ostringstream ostr;
for (auto i: iterable)
ostr << i << ",";
return ostr.str();
}
int main(int argc, const char * argv[]) {
cout << endl << "Range of ints: " << endl;
for (int i: range(5,9))
cout << i; // 5678
cout << endl << "Range of doubles: " << endl;
for (double i: range(5.1,9.1))
cout << i << " "; // 5.1 6.1 7.1 8.1
cout << endl << "Range of chars: " << endl;
for (char i: range('a','e'))
cout << i << " "; // a b c d
// Note: this example works even without your code
// It shows that a string is also an "iterable" - it can be iterated with a for-each loop.
cout << endl << "Standard string: " << endl;
for (char i: string("hello"))
cout << i << " "; // prints h e l l o
cout << endl << "Chain of two ranges: " << endl;
for (int i: chain(range(1,4), range(5,8)))
cout << i; // prints 123567
cout << endl << "Chain of a range and a string: " << endl;
for (char i: chain(range('a','e'), string("hello")))
cout << i; // abcdhello
cout << endl << "Zip a range of ints and a string (must be of the same size)" << endl;
for (auto pair: zip(range(1,6), string("hello")))
cout << pair << " "; // 1,h 2,e 3,l 4,l 5,o
cout << endl << "Zip of zips" << endl;
for (auto pair: zip(zip(range(1,4), string("xyz")),zip(string("abc"),range(6,9))))
cout << pair << " "; // 1,x,a,6 2,y,b,7 3,z,c,8
cout << endl << "Cartesian product of a range of ints and a string (can be of different sizes)" << endl;
for (auto pair: product(range(1,4), string("hello")))
cout << pair << " "; // 1,h 1,e 1,l 1,l 1,o 2,h 2,e 2,l 2,l 2,o 3,h 3,e 3,l 3,l 3,o
cout << endl << "Power-set of range of ints " << endl;
for (auto subset: powerset(range(1,4)))
cout << subset; // {}{1}{2}{1,2}{3}{1,3}{2,3}{1,2,3}
cout << endl << "Power-set of chain " << endl;
for (auto subset: powerset(chain(range('a','c'),range('x','z'))))
cout << subset; // {}{a}{b}{a,b}{x}{a,x}{b,x}{a,b,x}{y}{a,y}{b,y}{a,b,y}{x,y}{a,x,y}{b,x,y}{a,b,x,y}
// cout << iterable_to_string(powerset(chain(range('a','c'),range('x','z')))) << endl;
cout << endl;
}