From 2e6fc13b1e99a6d9de763ee93ed7f3140f908530 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Sun, 25 Jul 2021 12:56:52 -0600 Subject: [PATCH] AK: Implement any_of using common implementation Problem: - `any_of` is implemented in 2 different ways, one for the entire container and a different implementation for a partial container using iterators. Solution: - Follow the "don't repeat yourself" (DRY) idiom and implement the entire container version in terms of the partial version. --- AK/AnyOf.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/AK/AnyOf.h b/AK/AnyOf.h index f651f3eec6..5d851a97fe 100644 --- a/AK/AnyOf.h +++ b/AK/AnyOf.h @@ -24,11 +24,7 @@ constexpr bool any_of( template constexpr bool any_of(Container&& container, auto const& predicate) { - for (auto&& entry : container) { - if (predicate(entry)) - return true; - } - return false; + return any_of(container.begin(), container.end(), predicate); } }