From: Mikko Rasa Date: Mon, 19 Dec 2022 10:06:20 +0000 (+0200) Subject: Add an algorithm to check for existence of a value in a container X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=de6ba04370a505484747a81c74ad8f532b4b88e6;p=libs%2Fcore.git Add an algorithm to check for existence of a value in a container --- 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) {