diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-11-01 18:21:30 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-11-01 18:21:30 +0100 |
commit | 48f8f79317a04891e2becd859363add6eb2d6444 (patch) | |
tree | f92d080a4b552df405470662a31fc5e4a923882d /include/stdalgo.h | |
parent | fbc73e20784b055485f676096e758d6aeed62e0c (diff) |
Add stdalgo::isin() and use it to simplify code
Diffstat (limited to 'include/stdalgo.h')
-rw-r--r-- | include/stdalgo.h | 12 |
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()); + } } |