8000 clean up · Z80coder/datalog-cpp@0876523 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0876523

Browse files
author
wright
committed
clean up
1 parent 5d805c0 commit 0876523

File tree

2 files changed

+82
-237
lines changed

2 files changed

+82
-237
lines changed

src/Datalog.h

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,9 @@ struct Relation : tuple<Ts...>
9494
typedef tuple<Ts...> TupleType;
9595
typedef tuple<VariableOrValue<Ts>...> Atom;
9696
using tuple<Ts...>::tuple;
97-
struct compare
98-
{
99-
bool operator()(const Relation &lhs, const Relation &rhs) const
100-
{
101-
return lhs < rhs;
102-
}
103-
};
104-
typedef set<Relation, compare> Set;
97+
typedef set<Relation> Set;
10598
};
10699

107-
// TODO: why can't we use the apply pattern everywhere?
108-
109100
template <typename TUPLE_TYPE>
110101
static ostream &
111102
print(ostream &out, const TUPLE_TYPE &s)
@@ -125,19 +116,10 @@ static void unbind(const VariableOrValue<T> &VariableOrValue)
125116
}
126117
}
127118

128-
template <typename RELATION_TYPE, size_t... Is>
129-
static void unbind(const typename RELATION_TYPE::Atom &tuple,
130-
index_sequence<Is...>)
131-
{
132-
((unbind(get<Is>(tuple))), ...);
133-
}
134-
135119
template <typename... Ts>
136120
static void unbind(const tuple<VariableOrValue<Ts>...> &tuple)
137121
{
138-
auto indexSequence = make_index_sequence<
139-
tuple_size<typename Relation<Ts...>::Atom>::value>{};
140-
unbind<Relation<Ts...>>(tuple, indexSequence);
122+
apply([](auto &&... args) { ((unbind(args), ...)); }, tuple);
141123
}
142124

143125
// bind 1 VariableOrValue with 1 Value
@@ -206,6 +188,7 @@ struct Rule
206188
typedef HEAD_RELATION HeadRelationType;
207189
typedef typename HEAD_RELATION::Atom HeadType;
208190
HeadType head;
191+
209192
typedef tuple<typename BODY_RELATIONs::Atom...> BodyType;
210193
BodyType body;
211194
typedef tuple<BODY_RELATIONs...> BodyRelations;
@@ -394,8 +377,7 @@ struct State
394377
static RelationsIteratorType initIterators(const SetsOfRelationsType &relations)
395378
{
396379
RelationsIteratorType iterators;
397-
initIterators(relations, iterators,
398-
make_index_sequence<tuple_size<RelationsIteratorType>::value>{});
380+
initIterators(relations, iterators, make_index_sequence<tuple_size<RelationsIteratorType>::value>{});
399381
return iterators;
400382
}
401383
};
@@ -408,18 +390,10 @@ struct State
408390
}
409391
};
410392

411-
template <typename RULE_TYPE, size_t... Is>
412-
static void unbind(const typename RULE_TYPE::BodyType &atoms,
413-
index_sequence<Is...>)
414-
{
415-
((unbind(get<Is>(atoms))), ...);
416-
}
417-
418393
template <typename RULE_TYPE>
419394
static void unbind(const typename RULE_TYPE::BodyType &atoms)
420395
{
421-
unbind<RULE_TYPE>(atoms,
422-
make_index_sequence<tuple_size<typename RULE_TYPE::BodyType>::value>{});
396+
apply([](auto &&... args) { ((unbind(args)), ...); }, atoms);
423397
}
424398

425399
template <size_t I, typename RULE_TYPE>

0 commit comments

Comments
 (0)
0