[PATCH] D28371: Add missing operators for iterator_facade_base
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 5 11:02:14 PST 2017
zturner created this revision.
zturner added a reviewer: chandlerc.
zturner added a subscriber: llvm-commits.
We were missing operators required to allow calling `std::distance`, as well as an `operator<` to match the existing `operator>`.
https://reviews.llvm.org/D28371
Files:
llvm/include/llvm/ADT/iterator.h
Index: llvm/include/llvm/ADT/iterator.h
===================================================================
--- llvm/include/llvm/ADT/iterator.h
+++ llvm/include/llvm/ADT/iterator.h
@@ -86,6 +86,12 @@
tmp -= n;
return tmp;
}
+ DifferenceTypeT operator-(const DerivedT &i) const {
+ static_assert(
+ IsRandomAccess,
+ "The '-' operator is only defined for random access iterators.");
+ return i - *static_cast<const DerivedT *>(this);
+ }
DerivedT &operator++() {
return static_cast<DerivedT *>(this)->operator+=(1);
@@ -114,6 +120,13 @@
return !static_cast<const DerivedT *>(this)->operator==(RHS);
}
+ bool operator<(const DerivedT &RHS) const {
+ static_assert(
+ IsRandomAccess,
+ "Relational operators are only defined for random access iterators.");
+ return !static_cast<const DerivedT *>(this)->operator>(RHS) &&
+ !static_cast<const DerivedT *>(this)->operator==(RHS);
+ }
bool operator>(const DerivedT &RHS) const {
static_assert(
IsRandomAccess,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28371.83276.patch
Type: text/x-patch
Size: 1060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170105/ebf8da87/attachment.bin>
More information about the llvm-commits
mailing list