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

AK: Find a value in any container offering iterators

Problem:
- `find` is implemented inside of each container. This coupling
  requires that each container needs to individually provide `find`.

Solution:
- Decouple the `find` functionality from the container. This allows
  provides a `find` algorithm which can work with all
  containers. Containers can still provide their own `find` in the
  case where it can be optimized.
- This also allows for searching sub-ranges of a container rather than
  the entire container as some of the container-specific member
  functions enforced.

Note:
- @davidstone's talk from 2015 C++Now conference entitled "Functions
  Want to be Free" encourages this style:
  (https://www.youtube.com/watch?v=_lVlC0xzXDc), but it does come at
  the cost of composability.
- A logical follow-on to this is to provide a mechanism to use a
  short-hand function which automatically searches the entire
  container. This could automatically use the container-provided
  version if available so that functions which provide their own
  optimized version get the benefit.
This commit is contained in:
Lenny Maiorani 2020-12-23 11:35:01 -07:00 committed by Andreas Kling
parent 04c6245fe8
commit 4333a9a8d6
4 changed files with 135 additions and 1 deletions

View file

@ -35,7 +35,7 @@ template<typename T>
struct GenericTraits {
using PeekType = T;
static constexpr bool is_trivial() { return false; }
static bool equals(const T& a, const T& b) { return a == b; }
static constexpr bool equals(const T& a, const T& b) { return a == b; }
};
template<typename T>