diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-07-25 17:19:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-25 17:19:11 +0200 |
commit | 2bdd8003d3a6e04d307d5201932e57bd1bb0217c (patch) | |
tree | 178982d5020d9c862093eb4758ad6614269698d0 | |
parent | 5248a902ef9d2e30802c3924afb19a74935adbef (diff) | |
parent | 70882a807074a521515d1525d83ed7321f982d7e (diff) | |
download | yosys-2bdd8003d3a6e04d307d5201932e57bd1bb0217c.tar.gz yosys-2bdd8003d3a6e04d307d5201932e57bd1bb0217c.tar.bz2 yosys-2bdd8003d3a6e04d307d5201932e57bd1bb0217c.zip |
Merge pull request #1219 from jakobwenzel/objIterator
made ObjectIterator comply with Iterator Interface
-rw-r--r-- | kernel/rtlil.h | 22 | ||||
-rw-r--r-- | kernel/yosys.h | 1 |
2 files changed, 20 insertions, 3 deletions
diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 82cbfaf28..712250b3e 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -420,8 +420,12 @@ 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 { + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; typename dict<RTLIL::IdString, T>::iterator it; dict<RTLIL::IdString, T> *list_p; int *refcount_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; } }; diff --git a/kernel/yosys.h b/kernel/yosys.h index c7b671724..84c797b2d 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -52,6 +52,7 @@ #include <stdexcept> #include <memory> #include <cmath> +#include <cstddef> #include <sstream> #include <fstream> |