-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (49 loc) · 1.18 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
#include <iostream>
#include <fstream>
#include <async/async.hpp>
#include <functional>
#include "utils.h"
using namespace std::placeholders;
template <class Str=std::string>
void streamFile(const char* path, async::task<Str>& task, async::stream<Str>& stream){
std::ifstream file{path};
if(!file.is_open())
task.stop("Could not open file");
while(file.good()){
Str tmp;
std::getline(file, tmp);
stream << tmp;
}
if(!file.eof())
task.stop("Stopped reading before EOF");
}
void testLoremIpsum(){
/*async::task<std::string> task([](async::task<std::string>& task, async::stream<std::string>& stream){
streamFile("../test.txt", task, stream);
});*/
async::task<std::string> task(std::bind(
streamFile<>,
"../test.txt", _1, _2
));
task->stream()
->filter(is_not_whitespace)
->forEach(cli::wrap::log("$[> ", " <]$\n"));
task->run()->wait();
}
void testNumber(){
async::task<std::string> task(std::bind(
streamFile<>,
"../num.txt", _1, _2
));
task->stream()
->filter(is_not_whitespace)
->filter(is_int<>)
->mapTo<int>(to_int<>)
->forEach(cli::wrap::log<int>("$> ", " <$"));
task->run()->wait();
}
int main() {
// testLoremIpsum();
testNumber();
return 0;
}