diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-03-24 16:39:20 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-03-24 16:39:20 +0100 |
commit | 6d9b2bfee07c906699faef4de5ad85787978be3a (patch) | |
tree | 43e0c435583af0fa02c99f871ba93f48581a14b1 /include | |
parent | 671a80a70be60ccad1c0176556487c09be810489 (diff) |
Make it possible to customize how SimpleExtItem should delete items
Diffstat (limited to 'include')
-rw-r--r-- | include/extensible.h | 14 | ||||
-rw-r--r-- | include/stdalgo.h | 12 |
2 files changed, 21 insertions, 5 deletions
diff --git a/include/extensible.h b/include/extensible.h index 0e1afdbdf..87fe65ccb 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -126,7 +126,7 @@ class CoreExport LocalExtItem : public ExtensionItem virtual void free(void* item) = 0; }; -template<typename T> +template <typename T, typename Del = stdalgo::defaultdeleter<T> > class SimpleExtItem : public LocalExtItem { public: @@ -147,24 +147,28 @@ class SimpleExtItem : public LocalExtItem { T* ptr = new T(value); T* old = static_cast<T*>(set_raw(container, ptr)); - delete old; + Del del; + del(old); } inline void set(Extensible* container, T* value) { T* old = static_cast<T*>(set_raw(container, value)); - delete old; + Del del; + del(old); } inline void unset(Extensible* container) { T* old = static_cast<T*>(unset_raw(container)); - delete old; + Del del; + del(old); } virtual void free(void* item) { - delete static_cast<T*>(item); + Del del; + del(static_cast<T*>(item)); } }; diff --git a/include/stdalgo.h b/include/stdalgo.h index 758845312..3cbb86350 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -63,4 +63,16 @@ namespace stdalgo return false; } } + + /** + * Deleter that uses operator delete to delete the item + */ + template <typename T> + struct defaultdeleter + { + void operator()(T* o) + { + delete o; + } + }; } |