Index: src/compiler/node.h |
diff --git a/src/compiler/node.h b/src/compiler/node.h |
index 2295b7b5e3e9dfba6a161ca8b9c6b768bf26ee16..804281e226b4ed1e7a506c52077afbed0fb1982d 100644 |
--- a/src/compiler/node.h |
+++ b/src/compiler/node.h |
@@ -278,27 +278,35 @@ class Edge { |
// A forward iterator to visit the edges for the input dependencies of a node.. |
-class Node::InputEdges::iterator { |
+class Node::InputEdges::iterator FINAL { |
public: |
typedef std::forward_iterator_tag iterator_category; |
- typedef int difference_type; |
+ typedef ptrdiff_t difference_type; |
typedef Edge value_type; |
typedef Edge* pointer; |
typedef Edge& reference; |
iterator(const Node::InputEdges::iterator& other) // NOLINT |
: input_(other.input_) {} |
- iterator() : input_(NULL) {} |
+ iterator() : input_(nullptr) {} |
Edge operator*() const { return Edge(input_); } |
bool operator==(const iterator& other) const { return Equals(other); } |
bool operator!=(const iterator& other) const { return !Equals(other); } |
+ iterator& operator+=(difference_type n) { |
+ DCHECK_NOT_NULL(input_); |
+ Edge const edge(input_); |
+ SetInput(edge.from(), input_->use->input_index + n); |
+ return *this; |
+ } |
iterator& operator++() { |
- DCHECK(input_ != NULL); |
- Edge edge(input_); |
- Node* from = edge.from(); |
- SetInput(from, input_->use->input_index + 1); |
+ (*this) += 1; |
return *this; |
} |
+ iterator operator+(difference_type n) const { |
+ iterator result(*this); |
+ result += n; |
+ return result; |
+ } |
iterator operator++(int) { |
iterator result(*this); |
++(*this); |
@@ -308,17 +316,17 @@ class Node::InputEdges::iterator { |
private: |
friend class Node; |
- explicit iterator(Node* from, int index = 0) : input_(NULL) { |
+ explicit iterator(Node* from, difference_type index = 0) { |
SetInput(from, index); |
} |
bool Equals(const iterator& other) const { return other.input_ == input_; } |
- void SetInput(Node* from, int index) { |
+ void SetInput(Node* from, difference_type index) { |
DCHECK(index >= 0 && index <= from->InputCount()); |
if (index < from->InputCount()) { |
- input_ = from->GetInputRecordPtr(index); |
+ input_ = from->GetInputRecordPtr(static_cast<int>(index)); |
} else { |
- input_ = NULL; |
+ input_ = nullptr; |
} |
} |
@@ -327,10 +335,10 @@ class Node::InputEdges::iterator { |
// A forward iterator to visit the inputs of a node. |
-class Node::Inputs::iterator { |
+class Node::Inputs::iterator FINAL { |
public: |
typedef std::forward_iterator_tag iterator_category; |
- typedef int difference_type; |
+ typedef ptrdiff_t difference_type; |
typedef Node* value_type; |
typedef Node** pointer; |
typedef Node*& reference; |
@@ -341,10 +349,19 @@ class Node::Inputs::iterator { |
Node* operator*() const { return (*iter_).to(); } |
bool operator==(const iterator& other) const { return Equals(other); } |
bool operator!=(const iterator& other) const { return !Equals(other); } |
+ iterator& operator+=(difference_type n) { |
+ iter_ += n; |
+ return *this; |
+ } |
iterator& operator++() { |
++iter_; |
return *this; |
} |
+ iterator operator+(difference_type n) const { |
+ iterator result(*this); |
+ result += n; |
+ return result; |
+ } |
iterator operator++(int) { |
iterator result(*this); |
++(*this); |