diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-11-01 18:17:04 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-11-01 18:17:04 +0100 |
commit | fbc73e20784b055485f676096e758d6aeed62e0c (patch) | |
tree | 8251c8473af414527becb989558a69c4e7dc49b4 /include | |
parent | 5fb509060fa7552a25efccad11595898d420d476 (diff) |
Add stdalgo::erase() and use it to simplify code
Diffstat (limited to 'include')
-rw-r--r-- | include/stdalgo.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/stdalgo.h b/include/stdalgo.h index afbd763fb..cb01a250a 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -94,4 +94,22 @@ namespace stdalgo { std::for_each(cont.begin(), cont.end(), defaultdeleter<T>()); } + + /** + * Remove an element from a container + * @param cont Container to remove the element from + * @param val Value of the element to look for and remove + * @return True if the element was found and removed, false otherwise + */ + template <template<typename, typename> class Cont, typename T, typename Alloc> + inline bool erase(Cont<T, Alloc>& cont, const T& val) + { + const typename Cont<T, Alloc>::iterator it = std::find(cont.begin(), cont.end(), val); + if (it != cont.end()) + { + cont.erase(it); + return true; + } + return false; + } } |