Fixes to ensure iterators satisfy the std::input_iterator concept
Migrating to std::ranges::begin and std::ranges::end requires iterators to actually satisfy the std::input_iterator concept. This CL batches up most of the trivial fixes to: - ensure iterator types are default constructible - ensure iterator types are assignable Bug: 337356049 Change-Id: If928855034830cf0dacd6e53c6ff1b40068e3e23 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5532895 Reviewed-by: danakj <danakj@chromium.org> Reviewed-by: Steve Kobes <skobes@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1301402}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
8534b49d1c
commit
be3ac3a80e
base
cc
third_party/blink/renderer
@ -113,6 +113,12 @@ class EnumSet {
|
||||
Iterator() : enums_(nullptr), i_(kValueCount) {}
|
||||
~Iterator() = default;
|
||||
|
||||
Iterator(const Iterator&) = default;
|
||||
Iterator& operator=(const Iterator&) = default;
|
||||
|
||||
Iterator(Iterator&&) = default;
|
||||
Iterator& operator=(Iterator&&) = default;
|
||||
|
||||
friend bool operator==(const Iterator& lhs, const Iterator& rhs) {
|
||||
return lhs.i_ == rhs.i_;
|
||||
}
|
||||
@ -159,7 +165,7 @@ class EnumSet {
|
||||
return i;
|
||||
}
|
||||
|
||||
const raw_ptr<const EnumBitSet> enums_;
|
||||
raw_ptr<const EnumBitSet> enums_;
|
||||
size_t i_;
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,7 @@ class BASE_EXPORT dict_iterator {
|
||||
reference ref_;
|
||||
};
|
||||
|
||||
constexpr dict_iterator() = default;
|
||||
explicit dict_iterator(DictStorage::iterator dict_iter);
|
||||
dict_iterator(const dict_iterator& dict_iter);
|
||||
dict_iterator& operator=(const dict_iterator& dict_iter);
|
||||
@ -99,6 +100,7 @@ class BASE_EXPORT const_dict_iterator {
|
||||
const reference ref_;
|
||||
};
|
||||
|
||||
constexpr const_dict_iterator() = default;
|
||||
explicit const_dict_iterator(DictStorage::const_iterator dict_iter);
|
||||
const_dict_iterator(const const_dict_iterator& dict_iter);
|
||||
const_dict_iterator& operator=(const const_dict_iterator& dict_iter);
|
||||
|
@ -193,6 +193,8 @@ class ListContainer {
|
||||
// This class is only defined to forward iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
constexpr Iterator() = default;
|
||||
|
||||
Iterator(ListContainerHelper::CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -238,6 +240,8 @@ class ListContainer {
|
||||
// This class is only defined to forward iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
constexpr ConstIterator() = default;
|
||||
|
||||
ConstIterator(ListContainerHelper::CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -286,6 +290,8 @@ class ListContainer {
|
||||
// This class is only defined to reverse iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
constexpr ReverseIterator() = default;
|
||||
|
||||
ReverseIterator(ListContainerHelper::CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -330,6 +336,8 @@ class ListContainer {
|
||||
// This class is only defined to reverse iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
constexpr ConstReverseIterator() = default;
|
||||
|
||||
ConstReverseIterator(ListContainerHelper::CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
|
@ -39,13 +39,15 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
struct CC_BASE_EXPORT PositionInCharAllocator {
|
||||
// `ptr_to_container` is not a raw_ptr<...> for performance reasons (based
|
||||
// on analysis of sampling profiler data and tab_search:top100:2020).
|
||||
RAW_PTR_EXCLUSION CharAllocator* ptr_to_container;
|
||||
RAW_PTR_EXCLUSION CharAllocator* ptr_to_container = nullptr;
|
||||
|
||||
size_t vector_index;
|
||||
size_t vector_index = 0;
|
||||
|
||||
// `item_iterator` is not a raw_ptr<...> for performance reasons (based on
|
||||
// analysis of sampling profiler data and tab_search:top100:2020).
|
||||
RAW_PTR_EXCLUSION char* item_iterator;
|
||||
RAW_PTR_EXCLUSION char* item_iterator = nullptr;
|
||||
|
||||
PositionInCharAllocator() = default;
|
||||
|
||||
PositionInCharAllocator(const PositionInCharAllocator& other);
|
||||
PositionInCharAllocator& operator=(const PositionInCharAllocator& other);
|
||||
@ -67,6 +69,8 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
// This class is only defined to forward iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
Iterator() = default;
|
||||
|
||||
Iterator(CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -80,13 +84,15 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
// is used to avoid double increment at places an index reference is
|
||||
// needed. For iterator this means begin() corresponds to index 0 and end()
|
||||
// corresponds to index |size|.
|
||||
size_t index_;
|
||||
size_t index_ = 0;
|
||||
};
|
||||
|
||||
class CC_BASE_EXPORT ConstIterator : public PositionInCharAllocator {
|
||||
// This class is only defined to forward iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
ConstIterator() = default;
|
||||
|
||||
ConstIterator(CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -101,13 +107,15 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
// is used to avoid double increment at places an index reference is
|
||||
// needed. For iterator this means begin() corresponds to index 0 and end()
|
||||
// corresponds to index |size|.
|
||||
size_t index_;
|
||||
size_t index_ = 0;
|
||||
};
|
||||
|
||||
class CC_BASE_EXPORT ReverseIterator : public PositionInCharAllocator {
|
||||
// This class is only defined to reverse iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
ReverseIterator() = default;
|
||||
|
||||
ReverseIterator(CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -121,13 +129,15 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
// is used to avoid double increment at places an index reference is
|
||||
// needed. For reverse iterator this means rbegin() corresponds to index 0
|
||||
// and rend() corresponds to index |size|.
|
||||
size_t index_;
|
||||
size_t index_ = 0;
|
||||
};
|
||||
|
||||
class CC_BASE_EXPORT ConstReverseIterator : public PositionInCharAllocator {
|
||||
// This class is only defined to reverse iterate through
|
||||
// CharAllocator.
|
||||
public:
|
||||
ConstReverseIterator() = default;
|
||||
|
||||
ConstReverseIterator(CharAllocator* container,
|
||||
size_t vector_ind,
|
||||
char* item_iter,
|
||||
@ -142,7 +152,7 @@ class CC_BASE_EXPORT ListContainerHelper final {
|
||||
// is used to avoid double increment at places an index reference is
|
||||
// needed. For reverse iterator this means rbegin() corresponds to index 0
|
||||
// and rend() corresponds to index |size|.
|
||||
size_t index_;
|
||||
size_t index_ = 0;
|
||||
};
|
||||
|
||||
// Unlike the ListContainer methods, these do not invoke element destructors.
|
||||
|
@ -29,6 +29,8 @@ class PaintOpBufferIteratorBase {
|
||||
class CC_PAINT_EXPORT PaintOpBuffer::Iterator
|
||||
: public PaintOpBufferIteratorBase {
|
||||
public:
|
||||
constexpr Iterator() = default;
|
||||
|
||||
explicit Iterator(const PaintOpBuffer& buffer)
|
||||
: Iterator(buffer, buffer.data_.get(), 0u) {}
|
||||
|
||||
|
@ -232,6 +232,7 @@ class CC_EXPORT LayerTreeImpl {
|
||||
using pointer = LayerImpl**;
|
||||
using reference = LayerImpl*&;
|
||||
|
||||
constexpr IteratorAdapter() = default;
|
||||
explicit IteratorAdapter(Iterator it) : it_(it) {}
|
||||
bool operator==(IteratorAdapter o) const { return it_ == o.it_; }
|
||||
bool operator!=(IteratorAdapter o) const { return !(*this == o); }
|
||||
|
@ -708,6 +708,7 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
|
||||
using pointer = PhysicalBoxFragment*;
|
||||
using reference = PhysicalBoxFragment&;
|
||||
|
||||
constexpr Iterator() = default;
|
||||
explicit Iterator(const LayoutResultList::const_iterator& iterator)
|
||||
: iterator_(iterator) {}
|
||||
|
||||
|
@ -564,6 +564,8 @@ class CORE_EXPORT PhysicalFragment : public GarbageCollected<PhysicalFragment> {
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
constexpr ConstIterator() = default;
|
||||
|
||||
ConstIterator(const PhysicalFragmentLink* current, wtf_size_t size)
|
||||
: current_(current), end_(current + size) {
|
||||
SkipInvalidAndSetPostLayout();
|
||||
@ -603,8 +605,8 @@ class CORE_EXPORT PhysicalFragment : public GarbageCollected<PhysicalFragment> {
|
||||
}
|
||||
}
|
||||
|
||||
const PhysicalFragmentLink* current_;
|
||||
const PhysicalFragmentLink* end_;
|
||||
const PhysicalFragmentLink* current_ = nullptr;
|
||||
const PhysicalFragmentLink* end_ = nullptr;
|
||||
PhysicalFragmentLink post_layout_;
|
||||
};
|
||||
using const_iterator = ConstIterator;
|
||||
|
@ -85,6 +85,8 @@ class TestVector {
|
||||
using reference = T&;
|
||||
using value_type = T;
|
||||
|
||||
constexpr Iterator() = default;
|
||||
|
||||
Iterator(T* p, int stride) : p_(p), stride_(stride) {}
|
||||
|
||||
Iterator& operator++() {
|
||||
@ -110,8 +112,8 @@ class TestVector {
|
||||
T& operator*() const { return *p_; }
|
||||
|
||||
private:
|
||||
T* p_;
|
||||
size_t stride_;
|
||||
T* p_ = nullptr;
|
||||
size_t stride_ = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
|
13
third_party/blink/renderer/platform/wtf/deque.h
vendored
13
third_party/blink/renderer/platform/wtf/deque.h
vendored
@ -217,7 +217,7 @@ class DequeIteratorBase {
|
||||
DISALLOW_NEW();
|
||||
|
||||
protected:
|
||||
DequeIteratorBase();
|
||||
constexpr DequeIteratorBase() = default;
|
||||
DequeIteratorBase(const Deque<T, inlineCapacity, Allocator>*, wtf_size_t);
|
||||
DequeIteratorBase(const DequeIteratorBase&);
|
||||
DequeIteratorBase& operator=(const DequeIteratorBase<T, 0, Allocator>&);
|
||||
@ -234,8 +234,8 @@ class DequeIteratorBase {
|
||||
bool IsEqual(const DequeIteratorBase&) const;
|
||||
|
||||
private:
|
||||
Deque<T, inlineCapacity, Allocator>* deque_;
|
||||
unsigned index_;
|
||||
Deque<T, inlineCapacity, Allocator>* deque_ = nullptr;
|
||||
unsigned index_ = 0;
|
||||
|
||||
friend class Deque<T, inlineCapacity, Allocator>;
|
||||
};
|
||||
@ -255,7 +255,7 @@ class DequeIterator : public DequeIteratorBase<T, inlineCapacity, Allocator> {
|
||||
typedef T& reference;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
DequeIterator() = default;
|
||||
constexpr DequeIterator() = default;
|
||||
DequeIterator(Deque<T, inlineCapacity, Allocator>* deque, wtf_size_t index)
|
||||
: Base(deque, index) {}
|
||||
|
||||
@ -311,6 +311,7 @@ class DequeConstIterator
|
||||
typedef const T& reference;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
constexpr DequeConstIterator() = default;
|
||||
DequeConstIterator(const Deque<T, inlineCapacity, Allocator>* deque,
|
||||
wtf_size_t index)
|
||||
: Base(deque, index) {}
|
||||
@ -667,10 +668,6 @@ inline void Deque<T, inlineCapacity, Allocator>::erase(wtf_size_t position) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, wtf_size_t inlineCapacity, typename Allocator>
|
||||
inline DequeIteratorBase<T, inlineCapacity, Allocator>::DequeIteratorBase()
|
||||
: deque_(nullptr) {}
|
||||
|
||||
template <typename T, wtf_size_t inlineCapacity, typename Allocator>
|
||||
inline DequeIteratorBase<T, inlineCapacity, Allocator>::DequeIteratorBase(
|
||||
const Deque<T, inlineCapacity, Allocator>* deque,
|
||||
|
Reference in New Issue
Block a user