X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Falgorithm.h;h=43bbaeeb2c00ace3199beae6b1af8052cd0bfb51;hb=HEAD;hp=51c2369d623b58790f4ca556018d0162cb96a185;hpb=85ef592fb1eab68283b12607701e4fb9b9014630;p=libs%2Fcore.git diff --git a/source/core/algorithm.h b/source/core/algorithm.h index 51c2369..43bbaee 100644 --- a/source/core/algorithm.h +++ b/source/core/algorithm.h @@ -2,6 +2,7 @@ #define MSP_CORE_ALGORITHM_H_ #include +#include namespace Msp { @@ -29,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) { @@ -107,33 +122,32 @@ struct MemberMatch const T &value; T C::*mem_ptr; - MemberMatch(const T &v, T C::*p): value(v), mem_ptr(p) { } - bool operator()(const C &obj) { return obj.*mem_ptr==value; } }; template inline typename Container::iterator find_member(Container &cont, const T &value, T Container::value_type::*mp) { - return find_if(cont, MemberMatch(value, mp)); + return find_if(cont, MemberMatch{ value, mp }); } template inline typename Container::const_iterator find_member(const Container &cont, const T &value, T Container::value_type::*mp) { - return find_if(cont, MemberMatch(value, mp)); + return find_if(cont, MemberMatch{ value, mp }); } -template +template> struct MemberCompare { T C::*mem_ptr; + P pred; MemberCompare(T C::*p): mem_ptr(p) { } - bool operator()(const C &obj, const T &v) { return obj.*mem_ptr