made ObjectIterator extend std::iterator
authorJakob Wenzel <wenzel@rs.tu-darmstadt.de>
Wed, 24 Jul 2019 11:33:07 +0000 (13:33 +0200)
committerJakob Wenzel <wenzel@rs.tu-darmstadt.de>
Wed, 24 Jul 2019 14:35:40 +0000 (16:35 +0200)
this makes it possible to use std algorithms on them

kernel/rtlil.h
kernel/yosys.h

index 82cbfaf28ab6408a0a957add83cd8e1f07722e55..10225cff249baa3476147d78f9dc0977000f75dc 100644 (file)
@@ -420,7 +420,11 @@ namespace RTLIL
        // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
 
        template<typename T>
-       struct ObjIterator
+       struct ObjIterator : public std::iterator<std::forward_iterator_tag,
+               T,
+               ptrdiff_t,
+               T *,
+               T &>
        {
                typename dict<RTLIL::IdString, T>::iterator it;
                dict<RTLIL::IdString, T> *list_p;
@@ -474,13 +478,25 @@ namespace RTLIL
                        return it != other.it;
                }
 
-               inline void operator++() {
+
+               inline bool operator==(const RTLIL::ObjIterator<T> &other) const {
+                       return !(*this != other);
+               }
+
+               inline ObjIterator<T>& operator++() {
                        log_assert(list_p != nullptr);
                        if (++it == list_p->end()) {
                                (*refcount_p)--;
                                list_p = nullptr;
                                refcount_p = nullptr;
                        }
+                       return *this;
+               }
+
+               inline const ObjIterator<T> operator++(int) {
+                       ObjIterator<T> result(*this);
+                       ++(*this);
+                       return result;
                }
        };
 
index c7b67172429b155e82e30b68046b397e23d0fa4d..84c797b2dc60b43b1e679ad239a069d202379b52 100644 (file)
@@ -52,6 +52,7 @@
 #include <stdexcept>
 #include <memory>
 #include <cmath>
+#include <cstddef>
 
 #include <sstream>
 #include <fstream>