-
Notifications
You must be signed in to change notification settings - Fork 1
/
boolean_visitor.h
35 lines (32 loc) · 1.03 KB
/
boolean_visitor.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
#pragma once
#include "expression_type.h"
struct NotVisitor {
auto operator()(bool a) const -> ExpressionType { return !a; }
auto operator()(ExpressionType &a, ExpressionType &b) const
-> ExpressionType {
return std::visit(NotVisitor{}, a);
}
template <class T> auto operator()(T) const -> ExpressionType {
return std::monostate();
}
};
struct AndVisitor {
auto operator()(bool a, bool b) const -> ExpressionType { return a && b; }
auto operator()(ExpressionType &a, ExpressionType &b) const
-> ExpressionType {
return std::visit(AndVisitor{}, a, b);
}
template <class T, class U> auto operator()(T, U) const -> ExpressionType {
return std::monostate();
}
};
struct OrVisitor {
auto operator()(bool a, bool b) const -> ExpressionType { return a || b; }
auto operator()(ExpressionType &a, ExpressionType &b) const
-> ExpressionType {
return std::visit(AndVisitor{}, a, b);
}
template <class T, class U> auto operator()(T, U) const -> ExpressionType {
return std::monostate();
}
};