diff options
-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; + } + }; } |