mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
AK: Reimplement any_of in terms of find_if
Problem: - Now that a generic free-function form of `find_if` is implemented the code in `any_of` is redundant. Solution: - Follow the "don't repeat yourself" mantra and make the code DRY by implementing `any_of` in terms of `find_if`.
This commit is contained in:
parent
25c73159ce
commit
24225df979
Notes:
sideshowbarker
2024-07-18 12:00:20 +09:00
Author: https://github.com/ldm5180
Commit: 24225df979
Pull-request: https://github.com/SerenityOS/serenity/pull/8012
1 changed files with 2 additions and 6 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Find.h>
|
||||||
#include <AK/Iterator.h>
|
#include <AK/Iterator.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -16,12 +17,7 @@ constexpr bool any_of(
|
||||||
const SimpleIterator<Container, ValueType>& end,
|
const SimpleIterator<Container, ValueType>& end,
|
||||||
const auto& predicate)
|
const auto& predicate)
|
||||||
{
|
{
|
||||||
for (auto iter = begin; iter != end; ++iter) {
|
return find_if(begin, end, predicate) != end;
|
||||||
if (predicate(*iter)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue