From 24225df979e1976e89b7e18be71c14fbdcdbfc43 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Fri, 11 Jun 2021 17:57:46 -0600 Subject: [PATCH] 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`. --- AK/AnyOf.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/AK/AnyOf.h b/AK/AnyOf.h index 0875039644..201a875fda 100644 --- a/AK/AnyOf.h +++ b/AK/AnyOf.h @@ -6,6 +6,7 @@ #pragma once +#include #include namespace AK { @@ -16,12 +17,7 @@ constexpr bool any_of( const SimpleIterator& end, const auto& predicate) { - for (auto iter = begin; iter != end; ++iter) { - if (predicate(*iter)) { - return true; - } - } - return false; + return find_if(begin, end, predicate) != end; } }