[PATCH] D45853: (WIP) Alternate approach to reversing filtered iterators
Tim Shen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 20 13:58:08 PDT 2018
timshen added inline comments.
================
Comment at: include/llvm/ADT/STLExtras.h:324
+ assert(Payload && "Payload should be engaged when findPrevValid is called");
+ while (this->I != Payload->Begin && !Payload->Pred(*this->I))
+ BaseT::operator--();
----------------
I think it's better to have:
while (!Payload->Pred(*this->I))
Notice that as it is described in http://en.cppreference.com/w/cpp/concept/BidirectionalIterator, the precondition is "a is decrementable (there exists such b that a == ++b)". Therefore, there must be an iterator value that satisfies `Payload->Pred(*this->I)`. If users wrote a bug by decrementing on begin, I'd rather keep looping and let sanitizers catch it.
https://reviews.llvm.org/D45853
More information about the llvm-commits
mailing list