1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:47:35 +00:00

SinglyLinkedList: Implement find in terms of AK::find

Problem:
- The implementation of `find` is coupled to the implementation of
  `SinglyLinkedList`.

Solution:
- Decouple the implementation of `find` from the class by using a
  generic `find` algorithm.
This commit is contained in:
Lenny Maiorani 2021-01-10 11:27:41 -07:00 committed by Andreas Kling
parent 853cb8af5c
commit 1b2364846f
7 changed files with 106 additions and 30 deletions

View file

@ -27,6 +27,7 @@
#pragma once
#include <AK/SinglyLinkedList.h>
#include <AK/StdLibExtras.h>
namespace AK {
@ -106,16 +107,16 @@ public:
ConstIterator begin() const { return List::begin(); }
ConstIterator end() const { return List::end(); }
template<typename Finder>
ConstIterator find(Finder finder) const
template<typename TUnaryPredicate>
ConstIterator find(TUnaryPredicate&& pred) const
{
return List::find(finder);
return List::find_if(forward<TUnaryPredicate>(pred));
}
template<typename Finder>
Iterator find(Finder finder)
template<typename TUnaryPredicate>
Iterator find(TUnaryPredicate&& pred)
{
return List::find(finder);
return List::find_if(forward<TUnaryPredicate>(pred));
}
ConstIterator find(const T& value) const