Skip to content

Commit 630be48

Browse files
authored
Merge pull request #2558 from AlexandreSinger/feature-remove-std-iterator
Removed Simple Uses of STD Iterator
2 parents 75746eb + 5bfa640 commit 630be48

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

libs/librrgraph/src/base/rr_node_impl.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,35 @@
33
// This file provides the inline proxy implemenation for t_rr_node.
44
// See the t_rr_node class comment for additional details.
55

6-
#include "rr_node_types.h"
6+
#include <cstddef>
7+
#include <iterator>
78
#include "rr_node.h"
89
#include "rr_graph_storage.h"
910

10-
class node_idx_iterator : public std::iterator<std::bidirectional_iterator_tag, const t_rr_node> {
11+
class node_idx_iterator {
1112
public:
13+
using iterator_category = std::bidirectional_iterator_tag;
14+
using difference_type = std::ptrdiff_t;
15+
using value_type = const t_rr_node;
16+
using pointer = value_type*;
17+
using reference = value_type&;
18+
1219
node_idx_iterator(t_rr_node value)
1320
: value_(value) {}
1421

15-
iterator operator++() {
22+
node_idx_iterator& operator++() {
1623
value_.next_node();
1724
return *this;
1825
}
19-
iterator operator--() {
26+
node_idx_iterator& operator--() {
2027
value_.prev_node();
2128
return *this;
2229
}
2330
reference operator*() const { return value_; }
2431
pointer operator->() const { return &value_; }
2532

26-
friend bool operator==(const node_idx_iterator lhs, const node_idx_iterator rhs) { return lhs.value_.id() == rhs.value_.id(); }
27-
friend bool operator!=(const node_idx_iterator lhs, const node_idx_iterator rhs) { return !(lhs == rhs); }
33+
friend bool operator==(const node_idx_iterator& lhs, const node_idx_iterator& rhs) { return lhs.value_.id() == rhs.value_.id(); }
34+
friend bool operator!=(const node_idx_iterator& lhs, const node_idx_iterator& rhs) { return !(lhs == rhs); }
2835

2936
private:
3037
t_rr_node value_;

libs/librrgraph/src/base/rr_node_types.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RR_NODE_TYPES_H
22
#define RR_NODE_TYPES_H
33

4+
#include <cstddef>
5+
#include <iterator>
46
#include <string>
57
#include <vector>
68
#include <array>
@@ -64,23 +66,29 @@ typedef uint16_t t_edge_size;
6466
*
6567
* Used inconjunction with vtr::Range to return ranges of edge indices
6668
*/
67-
class edge_idx_iterator : public std::iterator<std::bidirectional_iterator_tag, t_edge_size> {
69+
class edge_idx_iterator {
6870
public:
71+
using iterator_category = std::bidirectional_iterator_tag;
72+
using difference_type = std::ptrdiff_t;
73+
using value_type = t_edge_size;
74+
using pointer = t_edge_size*;
75+
using reference = t_edge_size&;
76+
6977
edge_idx_iterator(value_type init)
7078
: value_(init) {}
71-
iterator operator++() {
79+
edge_idx_iterator& operator++() {
7280
value_ += 1;
7381
return *this;
7482
}
75-
iterator operator--() {
83+
edge_idx_iterator& operator--() {
7684
value_ -= 1;
7785
return *this;
7886
}
7987
reference operator*() { return value_; }
8088
pointer operator->() { return &value_; }
8189

82-
friend bool operator==(const edge_idx_iterator lhs, const edge_idx_iterator rhs) { return lhs.value_ == rhs.value_; }
83-
friend bool operator!=(const edge_idx_iterator lhs, const edge_idx_iterator rhs) { return !(lhs == rhs); }
90+
friend bool operator==(const edge_idx_iterator& lhs, const edge_idx_iterator& rhs) { return lhs.value_ == rhs.value_; }
91+
friend bool operator!=(const edge_idx_iterator& lhs, const edge_idx_iterator& rhs) { return !(lhs == rhs); }
8492

8593
private:
8694
value_type value_;

libs/libvtrutil/src/vtr_ragged_matrix.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef VTR_RAGGED_MATRIX_H
22
#define VTR_RAGGED_MATRIX_H
3+
#include <cstddef>
34
#include <vector>
45
#include <iterator>
56

@@ -212,8 +213,14 @@ class FlatRaggedMatrix {
212213
* uses a callback to determine row lengths.
213214
*/
214215
template<class Callback>
215-
class RowLengthIterator : public std::iterator<std::random_access_iterator_tag, size_t> {
216+
class RowLengthIterator {
216217
public:
218+
using iterator_category = std::random_access_iterator_tag;
219+
using difference_type = std::ptrdiff_t;
220+
using value_type = size_t;
221+
using pointer = size_t*;
222+
using reference = size_t&;
223+
217224
RowLengthIterator(size_t irow, Callback& callback)
218225
: irow_(irow)
219226
, callback_(callback) {}

0 commit comments

Comments
 (0)