mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 01:04:38 +03:00
SinglyLinkedListWithCount: Correctly pass args to append, insert_before, insert_after
Problem: - Using regular functions rather than function templates results in the arguments not being deduced. This then requires the same function to be written multiple times and for `move` to be used rather than `forward`. Solution: - Collapse multiple function overloads to a single function template with a deduced argument. This allows the argument to be a forwarding reference and bind to either an l-value or r-value and forward the value.
This commit is contained in:
parent
6e4e3a7612
commit
5cee5725e7
Notes:
sideshowbarker
2024-07-18 22:42:40 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/5cee5725e74 Pull-request: https://github.com/SerenityOS/serenity/pull/5193
@ -80,16 +80,11 @@ public:
|
||||
return List::take_first();
|
||||
}
|
||||
|
||||
void append(const T& value)
|
||||
template<typename U = T>
|
||||
void append(U&& value)
|
||||
{
|
||||
m_count++;
|
||||
return SinglyLinkedList<T>::append(value);
|
||||
}
|
||||
|
||||
void append(T&& value)
|
||||
{
|
||||
m_count++;
|
||||
return List::append(move(value));
|
||||
return List::append(forward<T>(value));
|
||||
}
|
||||
|
||||
bool contains_slow(const T& value) const
|
||||
@ -135,28 +130,18 @@ public:
|
||||
return List::remove(iterator);
|
||||
}
|
||||
|
||||
void insert_before(Iterator iterator, const T& value)
|
||||
template<typename U = T>
|
||||
void insert_before(Iterator iterator, U&& value)
|
||||
{
|
||||
m_count++;
|
||||
List::insert_before(iterator, value);
|
||||
List::insert_before(iterator, forward<T>(value));
|
||||
}
|
||||
|
||||
void insert_before(Iterator iterator, T&& value)
|
||||
template<typename U = T>
|
||||
void insert_after(Iterator iterator, U&& value)
|
||||
{
|
||||
m_count++;
|
||||
List::insert_before(iterator, move(value));
|
||||
}
|
||||
|
||||
void insert_after(Iterator iterator, const T& value)
|
||||
{
|
||||
m_count++;
|
||||
List::insert_after(iterator, value);
|
||||
}
|
||||
|
||||
void insert_after(Iterator iterator, T&& value)
|
||||
{
|
||||
m_count++;
|
||||
List::insert_after(iterator, move(value));
|
||||
List::insert_after(iterator, forward<T>(value));
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user