Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Simple Uses of STD Iterator #2558

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions libs/librrgraph/src/base/rr_node_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
// This file provides the inline proxy implemenation for t_rr_node.
// See the t_rr_node class comment for additional details.

#include "rr_node_types.h"
#include <cstddef>
#include <iterator>
#include "rr_node.h"
#include "rr_graph_storage.h"

class node_idx_iterator : public std::iterator<std::bidirectional_iterator_tag, const t_rr_node> {
class node_idx_iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = const t_rr_node;
using pointer = value_type*;
using reference = value_type&;

node_idx_iterator(t_rr_node value)
: value_(value) {}

iterator operator++() {
node_idx_iterator& operator++() {
value_.next_node();
return *this;
}
iterator operator--() {
node_idx_iterator& operator--() {
value_.prev_node();
return *this;
}
reference operator*() const { return value_; }
pointer operator->() const { return &value_; }

friend bool operator==(const node_idx_iterator lhs, const node_idx_iterator rhs) { return lhs.value_.id() == rhs.value_.id(); }
friend bool operator!=(const node_idx_iterator lhs, const node_idx_iterator rhs) { return !(lhs == rhs); }
friend bool operator==(const node_idx_iterator& lhs, const node_idx_iterator& rhs) { return lhs.value_.id() == rhs.value_.id(); }
friend bool operator!=(const node_idx_iterator& lhs, const node_idx_iterator& rhs) { return !(lhs == rhs); }

private:
t_rr_node value_;
Expand Down
18 changes: 13 additions & 5 deletions libs/librrgraph/src/base/rr_node_types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef RR_NODE_TYPES_H
#define RR_NODE_TYPES_H

#include <cstddef>
#include <iterator>
#include <string>
#include <vector>
#include <array>
Expand Down Expand Up @@ -64,23 +66,29 @@ typedef uint16_t t_edge_size;
*
* Used inconjunction with vtr::Range to return ranges of edge indices
*/
class edge_idx_iterator : public std::iterator<std::bidirectional_iterator_tag, t_edge_size> {
class edge_idx_iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = t_edge_size;
using pointer = t_edge_size*;
using reference = t_edge_size&;

edge_idx_iterator(value_type init)
: value_(init) {}
iterator operator++() {
edge_idx_iterator& operator++() {
value_ += 1;
return *this;
}
iterator operator--() {
edge_idx_iterator& operator--() {
value_ -= 1;
return *this;
}
reference operator*() { return value_; }
pointer operator->() { return &value_; }

friend bool operator==(const edge_idx_iterator lhs, const edge_idx_iterator rhs) { return lhs.value_ == rhs.value_; }
friend bool operator!=(const edge_idx_iterator lhs, const edge_idx_iterator rhs) { return !(lhs == rhs); }
friend bool operator==(const edge_idx_iterator& lhs, const edge_idx_iterator& rhs) { return lhs.value_ == rhs.value_; }
friend bool operator!=(const edge_idx_iterator& lhs, const edge_idx_iterator& rhs) { return !(lhs == rhs); }

private:
value_type value_;
Expand Down
9 changes: 8 additions & 1 deletion libs/libvtrutil/src/vtr_ragged_matrix.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef VTR_RAGGED_MATRIX_H
#define VTR_RAGGED_MATRIX_H
#include <cstddef>
#include <vector>
#include <iterator>

Expand Down Expand Up @@ -212,8 +213,14 @@ class FlatRaggedMatrix {
* uses a callback to determine row lengths.
*/
template<class Callback>
class RowLengthIterator : public std::iterator<std::random_access_iterator_tag, size_t> {
class RowLengthIterator {
public:
using iterator_category = std::random_access_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = size_t;
using pointer = size_t*;
using reference = size_t&;

RowLengthIterator(size_t irow, Callback& callback)
: irow_(irow)
, callback_(callback) {}
Expand Down
Loading