-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
111 lines (88 loc) · 2.16 KB
/
main.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <sstream>
#include <string>
#include <memory>
#include <algorithm>
#include <utility>
#include <vector>
#include "main.h"
#include <thread>
#include <scl/scl.hpp>
#include <fstream>
using namespace scl::tools;
using namespace scl::tools::iostream;
using namespace scl::concepts;
using namespace scl::exceptions;
using namespace scl::utils;
using namespace scl::utils::placeholder;
using namespace scl::stream;
using namespace scl::stream::creators;
using namespace scl::stream::operators;
using namespace scl::stream::terminators;
using namespace scl::http;
using namespace scl::async;
float threeToPi(const int& i){ return 0.14f + i; }
template <class T>
void logt(const T& t){
static auto l = scl::cli::wrap::log<T>("%> ", " <%");
l(t);
}
void logf(const float& f){
logt<float>(f);
}
void logs(const std::string& s){
logt<std::string>(s);
}
struct Person{
std::string name;
Person(const Person&) = default;
Person(Person&&) = default;
Person& operator=(const Person&) = default;
Person& operator=(Person&&) = default;
explicit Person(std::string name) : name{std::move(name)}{
}
std::string getName() const{ return this->name; }
bool operator<(const Person& rhs) const{
return this->name < rhs.name;
}
};
void testsStreamObj(){
std::vector<Person> p = {
Person{"jean"},
Person{"michel"},
Person{"denis"},
Person{"2"}
};
auto res = streamFrom(p)
| uniqueBy(&Person::getName)
| map(&Person::getName)
| map(+[](const std::string& s){ return s + " 42"; })
| pack::toVector();
std::for_each(std::begin(res), std::end(res), logs);
std::cout << nl;
}
void testStreamFile(){
std::ifstream file;
file.open("./main.h");
streamFrom(file)
| forEach(+[](const std::string& str){
std::cout << str << nl;
});
}
void testChannel(){
Channel<int> chan;
/*auto& sender = chan.sender();
auto& receiver = chan.receiver();
std::thread([&]{ sender.send(42); }).detach();
std::thread([&]{ std::cout << receiver.receive() << nl; }).join();*/
std::thread([&]{ chan << 42.99; }).detach();
std::thread([&]{
Optional<int> i;
chan >> i;
std::cout << *i << nl;
}).join();
}
int main(){
testChannel();
// testsStreamObj();
return 0;
}