diff options
author | vng <viktor.govako@gmail.com> | 2012-09-07 20:13:12 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:43:13 +0300 |
commit | 44c86c6e572a7308430d5c49da13a94bda2042fc (patch) | |
tree | cd042a2f90c95686daabce5395cc42e1de57f9ec /base/stl_add.hpp | |
parent | e874d2adbf248115a62b28427fcfbe39c96ceea9 (diff) |
Make range delete scope guard more generic.
Diffstat (limited to 'base/stl_add.hpp')
-rw-r--r-- | base/stl_add.hpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/base/stl_add.hpp b/base/stl_add.hpp index d85a94b63a..c118e6773f 100644 --- a/base/stl_add.hpp +++ b/base/stl_add.hpp @@ -111,17 +111,33 @@ struct DeleteFunctor } }; -template <class TContainer> class DeleteRangeGuard +namespace impl { - TContainer & m_cont; -public: - DeleteRangeGuard(TContainer & cont) : m_cont(cont) {} - ~DeleteRangeGuard() + template <class TContainer, class TDeletor> class DeleteRangeFunctor { - for_each(m_cont.begin(), m_cont.end(), DeleteFunctor()); - m_cont.clear(); - } -}; + TContainer & m_cont; + TDeletor m_deletor; + + public: + DeleteRangeFunctor(TContainer & cont, TDeletor const & deletor) + : m_cont(cont), m_deletor(deletor) + { + } + + void operator() () + { + for_each(m_cont.begin(), m_cont.end(), m_deletor); + m_cont.clear(); + } + }; +} + +template <class TContainer, class TDeletor> +impl::DeleteRangeFunctor<TContainer, TDeletor> +GetRangeDeletor(TContainer & cont, TDeletor const & deletor) +{ + return impl::DeleteRangeFunctor<TContainer, TDeletor>(cont, deletor); +} struct NoopFunctor { |