From: Mikko Rasa Date: Sat, 5 Nov 2016 11:28:12 +0000 (+0200) Subject: Add implementations of find and find_if that take a container X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=8ac74c1f54ccedb86b4cd1544e2251682c0e95c8;hp=7ca970e5db84020e4735afccf43ede4d52ac0bf0 Add implementations of find and find_if that take a container Rather than an iterator pair. Searching through an entire container is a very common use case. --- diff --git a/source/core/algorithm.h b/source/core/algorithm.h new file mode 100644 index 0000000..5d75763 --- /dev/null +++ b/source/core/algorithm.h @@ -0,0 +1,34 @@ +#ifndef MSP_CORE_ALGORITHM_H_ +#define MSP_CORE_ALGORITHM_H_ + +#include + +namespace Msp { + +template +typename Container::iterator find(Container &cont, const T &value) +{ + return std::find(cont.begin(), cont.end(), value); +} + +template +typename Container::const_iterator find(const Container &cont, const T &value) +{ + return std::find(cont.begin(), cont.end(), value); +} + +template +typename Container::iterator find_if(Container &cont, Predicate pred) +{ + return std::find_if(cont.begin(), cont.end(), pred); +} + +template +typename Container::const_iterator find_if(const Container &cont, Predicate pred) +{ + return std::find_if(cont.begin(), cont.end(), pred); +} + +} // namespace Msp + +#endif