diff options
Diffstat (limited to 'src/resp.hpp')
-rw-r--r-- | src/resp.hpp | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/src/resp.hpp b/src/resp.hpp index fd861aa..9e1e4f7 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -38,8 +38,6 @@ #include <boost/format.hpp> -#define FOREACH(IT, i, c) for (IT i = (c).begin(); i != (c).end(); ++i) -#define FOREACHP(IT, i, c) for (IT i = (c)->begin(); i != (c)->end(); ++i) #define THROW_IF(cond, error, ...) { if (cond) throw Error(error, __VA_ARGS__); } using namespace std; @@ -306,11 +304,11 @@ list_contains(const ATuple* head, const AST* child) { if (*head == *child) return true; - FOREACHP(ATuple::const_iterator, p, head) { - if (**p == *child) + for (const auto& p : *head) { + if (*p == *child) return true; - const ATuple* tup = (*p)->to_tuple(); + const ATuple* tup = p->to_tuple(); if (tup && list_contains(tup, child)) return true; } @@ -327,8 +325,8 @@ list_equals(const ATuple* lhs, const ATuple* rhs) return false; ATuple::const_iterator l = lhs->begin(); - FOREACHP(ATuple::const_iterator, r, rhs) - if (!(*(*l++) == *(*r))) + for (const auto& r : *rhs) + if (!(*(*l++) == *r)) return false; return true; } @@ -383,12 +381,12 @@ inline const ATuple* ATuple::replace(const AST* from, const AST* to) const { List copy; - FOREACHP(const_iterator, i, this) { - if (*i == from) { + for (auto i : *this) { + if (i == from) { copy.push_back(to); } else { - const ATuple* tup = (*i)->to_tuple(); - copy.push_back(tup ? tup->replace(from, to) : (*i)); + const ATuple* tup = i->to_tuple(); + copy.push_back(tup ? tup->replace(from, to) : i); } } copy.head->loc = loc; @@ -456,15 +454,15 @@ struct Env : public list< vector< pair<const char*, V> > > { return v; } V* ref(const ASymbol* key) { - for (typename Env::iterator f = this->begin(); f != this->end(); ++f) - for (typename Frame::iterator b = f->begin(); b != f->end(); ++b) - if (b->first == key->sym()) - return &b->second; + for (auto& f : *this) + for (auto& b : f) + if (b.first == key->sym()) + return &b.second; return NULL; } bool contains(const Frame& frame, const ASymbol* key) const { - for (typename Frame::const_iterator b = frame.begin(); b != frame.end(); ++b) - if (b->first == key->sym()) + for (const auto& b : frame) + if (b.first == key->sym()) return true; return false; } @@ -504,7 +502,7 @@ struct Macro { /// Parse Time Environment (really just a symbol table) struct PEnv : private map<const string, const char*> { PEnv() : symID(0) {} - ~PEnv() { FOREACHP(const_iterator, i, this) free(const_cast<char*>(i->second)); } + ~PEnv() { for (const auto& i : *this) free(const_cast<char*>(i.second)); } string gensymstr(const char* s="b") { return (format("_%s%d") % s % symID++).str(); } ASymbol* gensym(const char* s="b") { return sym(gensymstr(s)); } ASymbol* sym(const string& s, Cursor c=Cursor()) { @@ -599,17 +597,17 @@ struct Subst : public list<Constraint> { bool contains(const AST* type) const { if (find(type) != end()) return true; - FOREACHP(const_iterator, j, this) - if (*j->second == *type - || (AType::is_expr(j->second) && list_contains(j->second->as_tuple(), type))) + for (const auto& j : *this) + if (*j.second == *type + || (AType::is_expr(j.second) && list_contains(j.second->as_tuple(), type))) return true; return false; } }; inline ostream& operator<<(ostream& out, const Subst& s) { - for (Subst::const_iterator i = s.begin(); i != s.end(); ++i) - out << i->first << " => " << i->second << endl; + for (const auto& c : s) + out << c.first << " => " << c.second << endl; return out; } @@ -617,8 +615,8 @@ inline ostream& operator<<(ostream& out, const Subst& s) { struct Constraints : public list<Constraint> { Constraints() : list<Constraint>() {} explicit Constraints(const Subst& subst) : list<Constraint>() { - FOREACH(Subst::const_iterator, i, subst) - push_back(Constraint(i->first, i->second)); + for (const auto& i : subst) + push_back(Constraint(i.first, i.second)); } Constraints(const_iterator begin, const_iterator end) : list<Constraint>(begin, end) {} void constrain(TEnv& tenv, const AST* o, const AST* t); @@ -626,8 +624,8 @@ struct Constraints : public list<Constraint> { }; inline ostream& operator<<(ostream& out, const Constraints& c) { - for (Constraints::const_iterator i = c.begin(); i != c.end(); ++i) - out << i->first << " <= " << i->second << endl; + for (const auto& i : c) + out << i.first << " <= " << i.second << endl; return out; } @@ -770,12 +768,12 @@ struct CEnv { } const ATuple* typedReplace(const ATuple* in, const AST* from, const AST* to) { List copy; - FOREACHP(ATuple::const_iterator, i, in) { - if (*i == from) { + for (const auto& i : *in) { + if (i == from) { copy.push_back(to); } else { - const ATuple* tup = (*i)->to_tuple(); - copy.push_back(tup ? typedReplace(tup, from, to) : (*i)); + const ATuple* tup = i->to_tuple(); + copy.push_back(tup ? typedReplace(tup, from, to) : i); } } copy.head->loc = in->loc; |