Index: include/llvm/ADT/BitVector.h =================================================================== --- include/llvm/ADT/BitVector.h +++ include/llvm/ADT/BitVector.h @@ -15,6 +15,7 @@ #define LLVM_ADT_BITVECTOR_H #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/MathExtras.h" #include @@ -29,7 +30,10 @@ /// ForwardIterator for the bits that are set. /// Iterators get invalidated when resize / reserve is called. -template class const_set_bits_iterator_impl { +template +class const_set_bits_iterator_impl + : public iterator_facade_base, + std::forward_iterator_tag, unsigned> { const BitVectorT &Parent; int Current = 0; @@ -44,12 +48,8 @@ explicit const_set_bits_iterator_impl(const BitVectorT &Parent) : const_set_bits_iterator_impl(Parent, Parent.find_first()) {} const_set_bits_iterator_impl(const const_set_bits_iterator_impl &) = default; - - const_set_bits_iterator_impl operator++(int) { - auto Prev = *this; - advance(); - return Prev; - } + const_set_bits_iterator_impl & + operator=(const const_set_bits_iterator_impl &other) = default; const_set_bits_iterator_impl &operator++() { advance(); @@ -63,12 +63,6 @@ "Comparing iterators from different BitVectors"); return Current == Other.Current; } - - bool operator!=(const const_set_bits_iterator_impl &Other) const { - assert(&Parent == &Other.Parent && - "Comparing iterators from different BitVectors"); - return Current != Other.Current; - } }; class BitVector { Index: include/llvm/ADT/iterator.h =================================================================== --- include/llvm/ADT/iterator.h +++ include/llvm/ADT/iterator.h @@ -42,8 +42,11 @@ /// (All of the following methods) /// - DerivedT &operator=(const DerivedT &R); /// - bool operator==(const DerivedT &R) const; -/// - const T &operator*() const; -/// - T &operator*(); +/// - either +/// - const T &operator*() const; +/// - T &operator*(); +/// - or +/// - T operator*() const; /// - DerivedT &operator++(); /// /// Bidirectional Iterators: @@ -164,9 +167,18 @@ "Relational operators are only defined for random access iterators."); return !static_cast(this)->operator<(RHS); } - - PointerT operator->() { return &static_cast(this)->operator*(); } + PointerT operator->() { + static_assert( + std::is_reference(this)->operator*())>::value, + "operator-> is defined only on iterators returning a const T&"); + return &static_cast(this)->operator*(); + } PointerT operator->() const { + static_assert( + std::is_reference(this)->operator*())>::value, + "operator-> is defined only on iterators returning a const T&"); return &static_cast(this)->operator*(); } ReferenceProxy operator[](DifferenceTypeT n) {