Skip to content

Commit 3c61f36

Browse files
authored
Merge pull request #2461 from verilog-to-routing/id_range_operator
StrongIdIterator Operator Overloading
2 parents 6e34cdf + a117935 commit 3c61f36

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

libs/libvtrutil/src/vtr_strong_id_range.h

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,61 +88,59 @@ class StrongIdIterator {
8888
return StrongId(size_t(id_) + offset);
8989
}
9090

91-
///@brief + operator
92-
template<typename IdType>
93-
friend StrongIdIterator<IdType> operator+(
94-
const StrongIdIterator<IdType>& lhs,
95-
ssize_t n) {
96-
StrongIdIterator ret = lhs;
97-
ret += n;
98-
return ret;
99-
}
100-
101-
///@brief - operator
102-
template<typename IdType>
103-
friend StrongIdIterator<IdType> operator-(
104-
const StrongIdIterator<IdType>& lhs,
105-
ssize_t n) {
106-
StrongIdIterator ret = lhs;
107-
ret -= n;
108-
return ret;
109-
}
110-
11191
///@brief ~ operator
11292
template<typename IdType>
113-
friend ssize_t operator-(
114-
const StrongIdIterator<IdType>& lhs,
115-
const StrongIdIterator<IdType>& rhs) {
116-
VTR_ASSERT_SAFE(bool(lhs.id_));
117-
VTR_ASSERT_SAFE(bool(rhs.id_));
118-
119-
ssize_t ret = size_t(lhs.id_);
120-
ret -= size_t(rhs.id_);
93+
ssize_t operator-(const StrongIdIterator<IdType>& other) const {
94+
VTR_ASSERT_SAFE(bool(id_));
95+
VTR_ASSERT_SAFE(bool(other.id_));
96+
97+
ssize_t ret = size_t(id_);
98+
ret -= size_t(other.id_);
12199
return ret;
122100
}
123101

124102
///@brief == operator
125103
template<typename IdType>
126-
friend bool operator==(const StrongIdIterator<IdType>& lhs, const StrongIdIterator<IdType>& rhs) {
127-
return lhs.id_ == rhs.id_;
104+
bool operator==(const StrongIdIterator<IdType>& other) const {
105+
return id_ == other.id_;
128106
}
129107

130108
///@brief != operator
131109
template<typename IdType>
132-
friend bool operator!=(const StrongIdIterator<IdType>& lhs, const StrongIdIterator<IdType>& rhs) {
133-
return lhs.id_ != rhs.id_;
110+
bool operator!=(const StrongIdIterator<IdType>& other) const {
111+
return id_ != other.id_;
134112
}
135113

136114
///@brief < operator
137115
template<typename IdType>
138-
friend bool operator<(const StrongIdIterator<IdType>& lhs, const StrongIdIterator<IdType>& rhs) {
139-
return lhs.id_ < rhs.id_;
116+
bool operator<(const StrongIdIterator<IdType>& other) const {
117+
return id_ < other.id_;
140118
}
141119

142120
private:
143121
StrongId id_;
144122
};
145123

124+
///@brief + operator
125+
template<typename IdType>
126+
inline StrongIdIterator<IdType> operator+(
127+
const StrongIdIterator<IdType>& lhs,
128+
ssize_t n) {
129+
StrongIdIterator ret = lhs;
130+
ret += n;
131+
return ret;
132+
}
133+
134+
///@brief - operator
135+
template<typename IdType>
136+
inline StrongIdIterator<IdType> operator-(
137+
const StrongIdIterator<IdType>& lhs,
138+
ssize_t n) {
139+
StrongIdIterator ret = lhs;
140+
ret -= n;
141+
return ret;
142+
}
143+
146144
/**
147145
* @brief StrongIdRange class
148146
*

0 commit comments

Comments
 (0)