File tree Expand file tree Collapse file tree 2 files changed +52
-51
lines changed Expand file tree Collapse file tree 2 files changed +52
-51
lines changed Original file line number Diff line number Diff line change 9
9
#include < functional>
10
10
#include < cassert>
11
11
#include < iostream>
12
+ #include < tuple>
12
13
13
14
#include " tuple_hash.h"
14
15
#include " Variable.h"
@@ -18,6 +19,56 @@ namespace datalog
18
19
19
20
using namespace std ;
20
21
22
+ template <typename T>
23
+ Variable<T> *var ()
24
+ {
25
+ return new Variable<T>();
26
+ }
27
+
28
+ template <typename T>
29
+ T val (Variable<T> *t)
30
+ {
31
+ return t->value ();
32
+ }
33
+
34
+ template <typename T>
35
+ void deleteVar (Variable<T> *v)
36
+ {
37
+ delete v;
38
+ }
39
+
40
+ template <typename T>
41
+ void unbind (Variable<T> *t)
42
+ {
43
+ t->unbind ();
44
+ }
45
+
46
+ template <typename T>
47
+ void unbind (const T &t) {}
48
+
49
+ template <typename ... Ts>
50
+ void unbind (const tuple<Ts...> &tuple)
51
+ {
52
+ apply ([](auto &&... args) { ((unbind (args), ...)); }, tuple);
53
+ }
54
+
55
+ template <typename T>
56
+ bool bind (const T &a, const T &b)
57
+ {
58
+ return a == b;
59
+ }
60
+
61
+ template <typename T>
62
+ bool bind (const T &a, Variable<T> *const b)
63
+ {
64
+ if (b->isBound ())
65
+ {
66
+ return b->value () == a;
67
+ }
68
+ b->bind (a);
69
+ return true ;
70
+ }
71
+
21
72
template <typename GROUND_TYPE, typename ... Ts, size_t ... Is>
22
73
bool bind (const GROUND_TYPE &fact, const tuple<Ts...> &atom, index_sequence<Is...>)
23
74
{
Original file line number Diff line number Diff line change 1
1
#ifndef VARIABLE_H
2
2
#define VARIABLE_H
3
3
4
- #include < tuple >
4
+ #include < optional >
5
5
6
6
namespace datalog
7
7
{
@@ -56,56 +56,6 @@ struct Variable : optional<T>
56
56
}
57
57
};
58
58
59
- template <typename T>
60
- Variable<T> *var ()
61
- {
62
- return new Variable<T>();
63
- }
64
-
65
- template <typename T>
66
- T val (Variable<T> *t)
67
- {
68
- return t->value ();
69
- }
70
-
71
- template <typename T>
72
- void deleteVar (Variable<T> *v)
73
- {
74
- delete v;
75
- }
76
-
77
- template <typename T>
78
- void unbind
EB11
(Variable<T> *t)
79
- {
80
- t->unbind ();
81
- }
82
-
83
- template <typename T>
84
- void unbind (const T &t) {}
85
-
86
- template <typename ... Ts>
87
- void unbind (const tuple<Ts...> &tuple)
88
- {
89
- apply ([](auto &&... args) { ((unbind (args), ...)); }, tuple);
90
- }
91
-
92
- template <typename T>
93
- bool bind (const T &a, const T &b)
94
- {
95
- return a == b;
96
- }
97
-
98
- template <typename T>
99
- bool bind (const T &a, Variable<T> *const b)
100
- {
101
- if (b->isBound ())
102
- {
103
- return b->value () == a;
104
- }
105
- b->bind (a);
106
- return true ;
107
- }
108
-
109
59
} // namespace datalog
110
60
111
61
#endif
You can’t perform that action at this time.
0 commit comments