made ObjectIterator extend std::iterator

this makes it possible to use std algorithms on them
This commit is contained in:
Jakob Wenzel 2019-07-24 13:33:07 +02:00
parent a66f17b6a7
commit 25685a9a5b
2 changed files with 19 additions and 2 deletions

View 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;
}
};

View File

@ -52,6 +52,7 @@
#include <stdexcept>
#include <memory>
#include <cmath>
#include <cstddef>
#include <sstream>
#include <fstream>