summaryrefslogtreecommitdiff
path: root/include/stdalgo.h
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-11-01 18:21:30 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-11-01 18:21:30 +0100
commit48f8f79317a04891e2becd859363add6eb2d6444 (patch)
treef92d080a4b552df405470662a31fc5e4a923882d /include/stdalgo.h
parentfbc73e20784b055485f676096e758d6aeed62e0c (diff)
Add stdalgo::isin() and use it to simplify code
Diffstat (limited to 'include/stdalgo.h')
-rw-r--r--include/stdalgo.h12
1 files changed, 12 insertions, 0 deletions
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 <template<typename, typename> class Cont, typename T, typename Alloc>
+ inline bool isin(const Cont<T, Alloc>& cont, const T& val)
+ {
+ return (std::find(cont.begin(), cont.end(), val) != cont.end());
+ }
}