Skip to content

Commit 2fab15d

Browse files
ktfzygoloid
andauthored
Inline operator== and operator!= (#67958)
Avoid triggering -Wnon-template-friend on newer GCC. --------- Co-authored-by: Richard Smith <[email protected]>
1 parent 96dd50e commit 2fab15d

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

llvm/include/llvm/ADT/PagedVector.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,35 +209,33 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
209209
return PagePtr[ElementIdx % PageSize];
210210
}
211211

212-
friend bool operator==(MaterializedIterator const &LHS,
213-
MaterializedIterator const &RHS);
214-
friend bool operator!=(MaterializedIterator const &LHS,
215-
MaterializedIterator const &RHS);
212+
/// Equality operator.
213+
friend bool operator==(const MaterializedIterator &LHS,
214+
const MaterializedIterator &RHS) {
215+
return LHS.equals(RHS);
216+
}
216217

217218
[[nodiscard]] size_t getIndex() const { return ElementIdx; }
218-
};
219219

220-
/// Equality operator.
221-
friend bool operator==(MaterializedIterator const &LHS,
222-
MaterializedIterator const &RHS) {
223-
assert(LHS.PV == RHS.PV);
224-
// Make sure we are comparing either end iterators or iterators pointing
225-
// to materialized elements.
226-
// It should not be possible to build two iterators pointing to non
227-
// materialized elements.
228-
assert(LHS.ElementIdx == LHS.PV->Size ||
229-
(LHS.ElementIdx < LHS.PV->Size &&
230-
LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
231-
assert(RHS.ElementIdx == RHS.PV->Size ||
232-
(RHS.ElementIdx < RHS.PV->Size &&
233-
RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
234-
return LHS.ElementIdx == RHS.ElementIdx;
235-
}
220+
friend bool operator!=(const MaterializedIterator &LHS,
221+
const MaterializedIterator &RHS) {
222+
return !(LHS == RHS);
223+
}
236224

237-
friend bool operator!=(MaterializedIterator const &LHS,
238-
MaterializedIterator const &RHS) {
239-
return !(LHS == RHS);
240-
}
225+
private:
226+
void verify() const {
227+
assert(
228+
ElementIdx == PV->Size ||
229+
(ElementIdx < PV->Size && PV->PageToDataPtrs[ElementIdx / PageSize]));
230+
}
231+
232+
bool equals(const MaterializedIterator &Other) const {
233+
assert(PV == Other.PV);
234+
verify();
235+
Other.verify();
236+
return ElementIdx == Other.ElementIdx;
237+
}
238+
};
241239

242240
/// Iterators over the materialized elements of the vector.
243241
///

0 commit comments

Comments
 (0)