diff options
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -260,6 +260,9 @@ struct AType : public ATuple { } return true; } + bool operator<(const AType& rhs) const { + return kind < rhs.kind || id < rhs.id; + } bool operator==(const AST& rhs) const { const AType* rt = rhs.to<const AType*>(); if (!rt || kind != rt->kind) @@ -431,8 +434,8 @@ inline ostream& operator<<(ostream& out, const Constraints& c) { return out; } -struct Subst : public map<const AType*,AType*> { - Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); insert(make_pair(s, t)); } } +struct Subst : public map<const AType,AType*> { + Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); insert(make_pair(*s, t)); } } static Subst compose(const Subst& delta, const Subst& gamma); AST* apply(AST* ast) const { AType* in = ast->to<AType*>(); @@ -443,13 +446,12 @@ struct Subst : public map<const AType*,AType*> { out->push_back(apply(in->at(i))); return out; } else { - Subst copy(*this); - iterator i; - while ((i = copy.find(in)) != copy.end()) { - in = i->second; - copy.erase(i); + const_iterator i = find(*in); + if (i != end()) { + return i->second; + } else { + return in; } - return in; } } }; |