Skip to content

Commit

Permalink
Merge pull request #4062 from povik/iterator-c++17
Browse files Browse the repository at this point in the history
Remove deprecated `std::iterator`, fix iterator types
  • Loading branch information
jix authored Dec 11, 2023
2 parents 373b651 + 80b8cd1 commit fe686e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
35 changes: 30 additions & 5 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,19 @@ class dict
}

public:
class const_iterator : public std::iterator<std::forward_iterator_tag, std::pair<K, T>>
class const_iterator
{
friend class dict;
protected:
const dict *ptr;
int index;
const_iterator(const dict *ptr, int index) : ptr(ptr), index(index) { }
public:
typedef std::forward_iterator_tag iterator_category;
typedef std::pair<K, T> value_type;
typedef ptrdiff_t difference_type;
typedef std::pair<K, T>* pointer;
typedef std::pair<K, T>& reference;
const_iterator() { }
const_iterator operator++() { index--; return *this; }
const_iterator operator+=(int amt) { index -= amt; return *this; }
Expand All @@ -389,14 +394,19 @@ class dict
const std::pair<K, T> *operator->() const { return &ptr->entries[index].udata; }
};

class iterator : public std::iterator<std::forward_iterator_tag, std::pair<K, T>>
class iterator
{
friend class dict;
protected:
dict *ptr;
int index;
iterator(dict *ptr, int index) : ptr(ptr), index(index) { }
public:
typedef std::forward_iterator_tag iterator_category;
typedef std::pair<K, T> value_type;
typedef ptrdiff_t difference_type;
typedef std::pair<K, T>* pointer;
typedef std::pair<K, T>& reference;
iterator() { }
iterator operator++() { index--; return *this; }
iterator operator+=(int amt) { index -= amt; return *this; }
Expand Down Expand Up @@ -800,14 +810,19 @@ class pool
}

public:
class const_iterator : public std::iterator<std::forward_iterator_tag, K>
class const_iterator
{
friend class pool;
protected:
const pool *ptr;
int index;
const_iterator(const pool *ptr, int index) : ptr(ptr), index(index) { }
public:
typedef std::forward_iterator_tag iterator_category;
typedef K value_type;
typedef ptrdiff_t difference_type;
typedef K* pointer;
typedef K& reference;
const_iterator() { }
const_iterator operator++() { index--; return *this; }
bool operator==(const const_iterator &other) const { return index == other.index; }
Expand All @@ -816,14 +831,19 @@ class pool
const K *operator->() const { return &ptr->entries[index].udata; }
};

class iterator : public std::iterator<std::forward_iterator_tag, K>
class iterator
{
friend class pool;
protected:
pool *ptr;
int index;
iterator(pool *ptr, int index) : ptr(ptr), index(index) { }
public:
typedef std::forward_iterator_tag iterator_category;
typedef K value_type;
typedef ptrdiff_t difference_type;
typedef K* pointer;
typedef K& reference;
iterator() { }
iterator operator++() { index--; return *this; }
bool operator==(const iterator &other) const { return index == other.index; }
Expand Down Expand Up @@ -1021,14 +1041,19 @@ class idict
pool<K, OPS> database;

public:
class const_iterator : public std::iterator<std::forward_iterator_tag, K>
class const_iterator
{
friend class idict;
protected:
const idict &container;
int index;
const_iterator(const idict &container, int index) : container(container), index(index) { }
public:
typedef std::forward_iterator_tag iterator_category;
typedef K value_type;
typedef ptrdiff_t difference_type;
typedef K* pointer;
typedef K& reference;
const_iterator() { }
const_iterator operator++() { index++; return *this; }
bool operator==(const const_iterator &other) const { return index == other.index; }
Expand Down
16 changes: 14 additions & 2 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,14 @@ struct RTLIL::SigBit
unsigned int hash() const;
};

struct RTLIL::SigSpecIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
struct RTLIL::SigSpecIterator
{
typedef std::input_iterator_tag iterator_category;
typedef RTLIL::SigBit value_type;
typedef ptrdiff_t difference_type;
typedef RTLIL::SigBit* pointer;
typedef RTLIL::SigBit& reference;

RTLIL::SigSpec *sig_p;
int index;

Expand All @@ -814,8 +820,14 @@ struct RTLIL::SigSpecIterator : public std::iterator<std::input_iterator_tag, RT
inline void operator++() { index++; }
};

struct RTLIL::SigSpecConstIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
struct RTLIL::SigSpecConstIterator
{
typedef std::input_iterator_tag iterator_category;
typedef RTLIL::SigBit value_type;
typedef ptrdiff_t difference_type;
typedef RTLIL::SigBit* pointer;
typedef RTLIL::SigBit& reference;

const RTLIL::SigSpec *sig_p;
int index;

Expand Down

0 comments on commit fe686e7

Please sign in to comment.