X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fstdalgo.h;h=3e00a4cdcd93030cdb2d3c56e1b48dac24599261;hb=3ef3047681f0813d8f1d06939eaa2ef378d99505;hp=1ae5b8ae1098919779a4414b47ba343651750af6;hpb=facea197311f9dfbd9401b32b18cfd1245ff9be4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/stdalgo.h b/include/stdalgo.h index 1ae5b8ae1..3e00a4cdc 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -84,4 +84,44 @@ namespace stdalgo { void operator()(classbase* item); }; + + /** + * Deletes all elements in a container using operator delete + * @param cont The container containing the elements to delete + */ + template class Cont, typename T, typename Alloc> + inline void delete_all(const Cont& cont) + { + std::for_each(cont.begin(), cont.end(), defaultdeleter()); + } + + /** + * 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 class Cont, typename T, typename Alloc> + inline bool erase(Cont& cont, const T& val) + { + const typename Cont::iterator it = std::find(cont.begin(), cont.end(), val); + if (it != cont.end()) + { + cont.erase(it); + return true; + } + 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()); + } }