From de6ba04370a505484747a81c74ad8f532b4b88e6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Dec 2022 12:06:20 +0200 Subject: [PATCH] Add an algorithm to check for existence of a value in a container --- source/core/algorithm.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/core/algorithm.h b/source/core/algorithm.h index 251a81e..30ca267 100644 --- a/source/core/algorithm.h +++ b/source/core/algorithm.h @@ -30,6 +30,20 @@ inline typename Container::const_iterator find_if(const Container &cont, Predica return std::find_if(cont.begin(), cont.end(), pred); } +template +struct ValueMatch +{ + const T &value; + + bool operator()(const T &v) { return v==value; } +}; + +template +inline bool any_equals(Container &cont, const T &value) +{ + return std::any_of(cont.begin(), cont.end(), ValueMatch{value}); +} + template inline typename Container::iterator lower_bound(Container &cont, const T &value) { -- 2.43.0