From 48f8f79317a04891e2becd859363add6eb2d6444 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 1 Nov 2014 18:21:30 +0100 Subject: Add stdalgo::isin() and use it to simplify code --- include/stdalgo.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/stdalgo.h') diff --git a/include/stdalgo.h b/include/stdalgo.h index cb01a250a..3e00a4cdc 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -112,4 +112,16 @@ namespace stdalgo } return false; } + + /** + * Check if an element with the given value is in a container. Equivalent to (std::find(cont.begin(), cont.end(), val) != cont.end()). + * @param cont Container to find the element in + * @param val Value of the element to look for + * @return True if the element was found in the container, false otherwise + */ + template class Cont, typename T, typename Alloc> + inline bool isin(const Cont& cont, const T& val) + { + return (std::find(cont.begin(), cont.end(), val) != cont.end()); + } } -- cgit v1.2.3