Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1d6c26

Browse files
committed
move bind functions out
1 parent1094960 commita1d6c26

File tree

2 files changed

+52
-51
lines changed

2 files changed

+52
-51
lines changed

‎src/Datalog.h‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include<functional>
1010
#include<cassert>
1111
#include<iostream>
12+
#include<tuple>
1213

1314
#include"tuple_hash.h"
1415
#include"Variable.h"
@@ -18,6 +19,56 @@ namespace datalog
1819

1920
usingnamespacestd;
2021

22+
template<typename T>
23+
Variable<T> *var()
24+
{
25+
returnnew Variable<T>();
26+
}
27+
28+
template<typename T>
29+
Tval(Variable<T> *t)
30+
{
31+
return t->value();
32+
}
33+
34+
template<typename T>
35+
voiddeleteVar(Variable<T> *v)
36+
{
37+
delete v;
38+
}
39+
40+
template<typename T>
41+
voidunbind(Variable<T> *t)
42+
{
43+
t->unbind();
44+
}
45+
46+
template<typename T>
47+
voidunbind(const T &t) {}
48+
49+
template<typename... Ts>
50+
voidunbind(const tuple<Ts...> &tuple)
51+
{
52+
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
53+
}
54+
55+
template<typename T>
56+
boolbind(const T &a,const T &b)
57+
{
58+
return a == b;
59+
}
60+
61+
template<typename T>
62+
boolbind(const T &a, Variable<T> *const b)
63+
{
64+
if (b->isBound())
65+
{
66+
return b->value() == a;
67+
}
68+
b->bind(a);
69+
returntrue;
70+
}
71+
2172
template<typename GROUND_TYPE,typename ... Ts,size_t... Is>
2273
boolbind(const GROUND_TYPE &fact,const tuple<Ts...> &atom, index_sequence<Is...>)
2374
{

‎src/Variable.h‎

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef VARIABLE_H
22
#defineVARIABLE_H
33

4-
#include<tuple>
4+
#include<optional>
55

66
namespacedatalog
77
{
@@ -56,56 +56,6 @@ struct Variable : optional<T>
5656
}
5757
};
5858

59-
template<typename T>
60-
Variable<T> *var()
61-
{
62-
returnnew Variable<T>();
63-
}
64-
65-
template<typename T>
66-
Tval(Variable<T> *t)
67-
{
68-
return t->value();
69-
}
70-
71-
template<typename T>
72-
voiddeleteVar(Variable<T> *v)
73-
{
74-
delete v;
75-
}
76-
77-
template<typename T>
78-
voidunbind(Variable<T> *t)
79-
{
80-
t->unbind();
81-
}
82-
83-
template<typename T>
84-
voidunbind(const T &t) {}
85-
86-
template<typename... Ts>
87-
voidunbind(const tuple<Ts...> &tuple)
88-
{
89-
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
90-
}
91-
92-
template<typename T>
93-
boolbind(const T &a,const T &b)
94-
{
95-
return a == b;
96-
}
97-
98-
template<typename T>
99-
boolbind(const T &a, Variable<T> *const b)
100-
{
101-
if (b->isBound())
102-
{
103-
return b->value() == a;
104-
}
105-
b->bind(a);
106-
returntrue;
107-
}
108-
10959
}// namespace datalog
11060

11161
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp