forked from OSchip/llvm-project
[STLExtras] Make indexed_accessor_range operator== compatible with C++20
This would be ambigious with itself when C++20 tries to lookup the reversed form. I didn't find a use in LLVM, but MLIR does a lot of comparisons of ranges of different types.
This commit is contained in:
parent
8ba1421432
commit
c312f02594
|
@ -1181,13 +1181,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare this range with another.
|
/// Compare this range with another.
|
||||||
template <typename OtherT> bool operator==(const OtherT &other) const {
|
template <typename OtherT>
|
||||||
return size() ==
|
friend bool operator==(const indexed_accessor_range_base &lhs,
|
||||||
static_cast<size_t>(std::distance(other.begin(), other.end())) &&
|
const OtherT &rhs) {
|
||||||
std::equal(begin(), end(), other.begin());
|
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||||
}
|
}
|
||||||
template <typename OtherT> bool operator!=(const OtherT &other) const {
|
template <typename OtherT>
|
||||||
return !(*this == other);
|
friend bool operator!=(const indexed_accessor_range_base &lhs,
|
||||||
|
const OtherT &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the size of this range.
|
/// Return the size of this range.
|
||||||
|
|
|
@ -46,4 +46,18 @@ TEST(AccessorRange, SliceTest) {
|
||||||
compareData(range.slice(2, 3), data.slice(2, 3));
|
compareData(range.slice(2, 3), data.slice(2, 3));
|
||||||
compareData(range.slice(0, 5), data.slice(0, 5));
|
compareData(range.slice(0, 5), data.slice(0, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AccessorRange, EqualTest) {
|
||||||
|
int32_t rawData1[] = {0, 1, 2, 3, 4};
|
||||||
|
uint64_t rawData2[] = {0, 1, 2, 3, 4};
|
||||||
|
|
||||||
|
ArrayIndexedAccessorRange<int32_t> range1(rawData1, /*start=*/0,
|
||||||
|
/*numElements=*/5);
|
||||||
|
ArrayIndexedAccessorRange<uint64_t> range2(rawData2, /*start=*/0,
|
||||||
|
/*numElements=*/5);
|
||||||
|
EXPECT_TRUE(range1 == range2);
|
||||||
|
EXPECT_FALSE(range1 != range2);
|
||||||
|
EXPECT_TRUE(range2 == range1);
|
||||||
|
EXPECT_FALSE(range2 != range1);
|
||||||
|
}
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
Loading…
Reference in New Issue