hashlib, rtlil: Add `operator+=()` to `dict<>::iterator` and `dict<>::const_iterator...
authorAlberto Gonzalez <boqwxp@airmail.cc>
Wed, 17 Jun 2020 22:32:34 +0000 (22:32 +0000)
committerAlberto Gonzalez <boqwxp@airmail.cc>
Fri, 19 Jun 2020 17:44:29 +0000 (17:44 +0000)
kernel/hashlib.h
kernel/rtlil.h

index 5c87b55f537ac3020cb53fa5df57f5234baf0a66..52dfd12803d2403a78926aef7b59913cf3614fa8 100644 (file)
@@ -363,6 +363,7 @@ public:
        public:
                const_iterator() { }
                const_iterator operator++() { index--; return *this; }
+               const_iterator operator+=(int amt) { index -= amt; if(index < 0) index = -1; return *this; }
                bool operator<(const const_iterator &other) const { return index > other.index; }
                bool operator==(const const_iterator &other) const { return index == other.index; }
                bool operator!=(const const_iterator &other) const { return index != other.index; }
@@ -380,6 +381,7 @@ public:
        public:
                iterator() { }
                iterator operator++() { index--; return *this; }
+               iterator operator+=(int amt) { index -= amt; if(index < 0) index = -1; return *this; }
                bool operator<(const iterator &other) const { return index > other.index; }
                bool operator==(const iterator &other) const { return index == other.index; }
                bool operator!=(const iterator &other) const { return index != other.index; }
index f3dc3af68ed33613b0099b314006c598e36dc31c..147ec8a5b86965926b2fe0f902b015f315ab765d 100644 (file)
@@ -554,6 +554,29 @@ namespace RTLIL
                        return *this;
                }
 
+               inline ObjIterator<T>& operator+=(int amt) {
+                       log_assert(list_p != nullptr);
+                       it += amt;
+                       if (it == list_p->end()) {
+                               (*refcount_p)--;
+                               list_p = nullptr;
+                               refcount_p = nullptr;
+                       }
+                       return *this;
+               }
+
+               inline ObjIterator<T> operator+(int amt) {
+                       log_assert(list_p != nullptr);
+                       ObjIterator<T> new_obj(*this);
+                       new_obj.it += amt;
+                       if (new_obj.it == list_p->end()) {
+                               (*(new_obj.refcount_p))--;
+                               new_obj.list_p = nullptr;
+                               new_obj.refcount_p = nullptr;
+                       }
+                       return new_obj;
+               }
+
                inline const ObjIterator<T> operator++(int) {
                        ObjIterator<T> result(*this);
                        ++(*this);