-
Notifications
You must be signed in to change notification settings - Fork 0
/
BFExpression.h
59 lines (47 loc) · 1013 Bytes
/
BFExpression.h
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
// 2020 by Stephan Roslen
#ifndef _BFTMP__BFEXPRESSION_H_
#define _BFTMP__BFEXPRESSION_H_
#include "BFMachine.h"
namespace bf::expression {
template<typename... Exprs>
struct Expression {
static void work(Machine &machine) {
((void) Exprs::work(machine), ...);
}
template<typename T>
using AppendT = Expression<Exprs..., T>;
};
template<Machine::SignedElemType n>
struct Add {
static void work(Machine &machine) {
if constexpr (0 != n) {
machine.add(n);
}
}
};
struct Read {
static void work(Machine &machine) {
machine.read();
}
};
struct Write {
static void work(Machine &machine) {
machine.write();
}
};
template<Machine::SignedIdxType n>
struct Move {
static void work(Machine &machine) {
if constexpr (0 != n) {
machine.move(n);
}
}
};
template<typename Expr>
struct Loop {
static void work(Machine &machine) {
machine.loop([&]() { Expr::work(machine); });
}
};
}// namespace bf::expression
#endif// _BFTMP__BFEXPRESSION_H_