8000 add var decl convenience function · Z80coder/datalog-cpp@13956c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13956c9

Browse files
author
wright
committed
add var decl convenience function
1 parent 896a45e commit 13956c9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Datalog.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ struct Variable : optional<T>
4040
}
4141
};
4242

43+
// TODO: use auto more for return type of functions
44+
45+
template<typename T>
46+
Variable<T>* var() {
47+
return new Variable<T>();
48+
}
49+
50+
template<typename T>
51+
void deleteVar(Variable<T>* v) {
52+
delete v;
53+
}
54+
4355
template <typename T>
4456
static void unbind(const T& t) {}
4557

tests/types_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ bool test1()
3333
{thor, god}};
3434

3535
// Rule
36-
Variable<Name> x;
37-
auto rule1 = rule(atom<Mortal>(&x), atom<Thing>(&x, person));
36+
auto x = var<Name>();
37+
auto rule1 = rule(atom<Mortal>(x), atom<Thing>(x, person));
3838

3939
State<Thing, Mortal> state{things, {}};
4040

@@ -45,6 +45,8 @@ bool test1()
4545
state = fixPoint(rules, state);
4646
cout << "after = " << state << endl;
4747

48+
deleteVar(x);
49+
4850
return true;
4951
}
5052

0 commit comments

Comments
 (0)
0