[PATCH] D84690: Make iterators of BitVector easier to use by inheriting iterator_facade_base

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 27 13:56:14 PDT 2020


dblaikie accepted this revision.
dblaikie added inline comments.
This revision is now accepted and ready to land.


================
Comment at: llvm/include/llvm/ADT/BitVector.h:36
+          const_set_bits_iterator_impl<BitVectorT>, std::forward_iterator_tag,
+          unsigned, std::ptrdiff_t, const unsigned *, const unsigned &> {
   const BitVectorT &Parent;
----------------
Looks like this isn't a forward iterator - it's an input iterator.

A forward iterator requires:

"The type std::iterator_traits<It>::reference must be exactly
T& if It satisfies LegacyOutputIterator (It is mutable)
const T& otherwise (It is constant),"

And that the return type of "op*" is referenec.

Since the return type of op* is unsigned, this could be an input iterator.

Or, I guess, the return type could be changed, since there is ongoing storage for the value (so long as the iterator isn't incremented - but that gets complicated with reverse iterators... ).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84690/new/

https://reviews.llvm.org/D84690





More information about the llvm-commits mailing list