forked from notepadqq/notepadqq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.cpp
48 lines (39 loc) · 1.23 KB
/
globals.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
#include "include/globals.h"
#include <QTextStream>
#include <QtPromise>
using namespace QtPromise;
void print(QString string)
{
static QTextStream ts(stdout);
ts << string;
ts.flush();
}
void println(QString string)
{
print(string + "\n");
}
void printerr(QString string)
{
static QTextStream ts(stderr);
ts << string;
ts.flush();
}
void printerrln(QString string)
{
printerr(string + "\n");
}
QPromise<PForResult::Enum> pFor(int start, int end, std::function<QPromise<PForResult::Enum>(int, QPromise<PForResult::Enum>, QPromise<PForResult::Enum>)> iteration) {
QPromise<PForResult::Enum> p = QPromise<PForResult::Enum>::resolve(PForResult::Continue);
for (int i = start; i < end; i++) {
p = p.then([=](PForResult::Enum result){
const auto _break = QPromise<PForResult::Enum>::resolve(PForResult::Break);
const auto _continue = QPromise<PForResult::Enum>::resolve(PForResult::Continue);
if (result == PForResult::Break) {
return _break; // TODO It is inefficient to transfer the "Break" message all to the end of the loop
} else {
return iteration(i, _break, _continue);
}
});
}
return p;
}