-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (59 loc) · 1.99 KB
/
Copy pathmain.cpp
File metadata and controls
68 lines (59 loc) · 1.99 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
68
#include <gtest/gtest.h>
#include "Promise.h"
#include "FlattenTuple.h"
#include <ostream>
using namespace std;
template<class Ch, class Tr, typename T>
decltype(auto) operator<<(std::basic_ostream<Ch, Tr> &os,
const vector<T> &t) {
os << "[ ";
for (auto &i: t) {
os << i;
if (i != t.back())
os << ", ";
}
return os << "]";
}
template<class Ch, class Tr, typename T, typename L>
decltype(auto) operator<<(std::basic_ostream<Ch, Tr> &os,
const map<T, L> &t) {
os << "[ ";
for (auto &i: t) {
os << "{ " << i.first << ": " << i.second << "}, ";
}
return os << "]";
}
template<class Ch, class Tr, class Tuple, std::size_t... Is>
void print_tuple_impl(std::basic_ostream<Ch, Tr> &os,
const Tuple &t,
std::index_sequence<Is...>) {
((os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), ...);
}
template<class Ch, class Tr, class... Args>
decltype(auto) operator<<(std::basic_ostream<Ch, Tr> &os,
const std::tuple<Args...> &t) {
os << "(";
print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
return os << ")";
}
int main(int argc, char *argv[]) {
int integer;
Promise<int> promiseInt;
Promise<std::vector<int>> promiseVector;
Promise<std::map<std::string, int>> promiseMap;
Promise<Future<std::vector<int>>> promiseFuture;
auto t = make_tuple(integer, promiseInt.getFuture(), promiseFuture.getFuture(), promiseMap.getFuture());
vector<int> k = {1, 2, 3, 4, 5};
map<std::string, int> k2 = {{"first", 11},
{"second", 22},
{"third", 33}};
integer = 0;
promiseInt.set(1);
promiseVector.set(k);
promiseMap.set(k2);
promiseFuture.set(std::move(promiseVector.getFuture()));
auto s = flattenTuple(move(t));
cout << s.get() << endl;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}