AK: Expose SinglyLinkedListIterator constructor

This commit replaces SinglyLinkedListIterator::universal_end() with an
empty SinglyLinkedListIterator(). Piano needs this in order to
initialize a member array of iterators without 84 lines of
universal_end().
This commit is contained in:
William McPherson 2020-02-26 23:49:58 +11:00 committed by Andreas Kling
parent 05ce8586ea
commit 121e7306c3
2 changed files with 5 additions and 5 deletions

View file

@ -79,7 +79,7 @@ public:
private:
friend HashTableType;
explicit HashTableIterator(HashTableType& table, bool is_end, BucketIteratorType bucket_iterator = BucketIteratorType::universal_end(), size_t bucket_index = 0)
explicit HashTableIterator(HashTableType& table, bool is_end, BucketIteratorType bucket_iterator = {}, size_t bucket_index = 0)
: m_table(table)
, m_bucket_index(bucket_index)
, m_is_end(is_end)
@ -87,7 +87,7 @@ private:
{
ASSERT(!table.m_clearing);
ASSERT(!table.m_rehashing);
if (!is_end && !m_table.is_empty() && !(m_bucket_iterator != BucketIteratorType::universal_end())) {
if (!is_end && !m_table.is_empty() && m_bucket_iterator.is_end()) {
m_bucket_iterator = m_table.bucket(0).begin();
if (m_bucket_iterator.is_end())
skip_to_next();

View file

@ -34,6 +34,7 @@ namespace AK {
template<typename ListType, typename ElementType>
class SinglyLinkedListIterator {
public:
SinglyLinkedListIterator() {}
bool operator!=(const SinglyLinkedListIterator& other) const { return m_node != other.m_node; }
SinglyLinkedListIterator& operator++()
{
@ -44,7 +45,6 @@ public:
ElementType& operator*() { return m_node->value; }
ElementType* operator->() { return &m_node->value; }
bool is_end() const { return !m_node; }
static SinglyLinkedListIterator universal_end() { return SinglyLinkedListIterator(nullptr); }
private:
friend ListType;
@ -160,12 +160,12 @@ public:
using Iterator = SinglyLinkedListIterator<SinglyLinkedList, T>;
friend Iterator;
Iterator begin() { return Iterator(m_head); }
Iterator end() { return Iterator::universal_end(); }
Iterator end() { return {}; }
using ConstIterator = SinglyLinkedListIterator<const SinglyLinkedList, const T>;
friend ConstIterator;
ConstIterator begin() const { return ConstIterator(m_head); }
ConstIterator end() const { return ConstIterator::universal_end(); }
ConstIterator end() const { return {}; }
template<typename Finder>
ConstIterator find(Finder finder) const