Index: src/list.h |
diff --git a/src/list.h b/src/list.h |
index 0e4e35bb41b78b3ff5aa8b106ea284d1e4ded91c..d64256887b1d2822e9e571cc31ded21f87fa7d47 100644 |
--- a/src/list.h |
+++ b/src/list.h |
@@ -48,13 +48,15 @@ namespace internal { |
// template <typename T, |
// class AllocationPolicy = FreeStoreAllocationPolicy> class List; |
template <typename T, class AllocationPolicy> |
-class List { |
+class List : private AllocationPolicy::Deleter { |
public: |
- explicit List(AllocationPolicy allocator = AllocationPolicy()) { |
+ explicit List(AllocationPolicy allocator = AllocationPolicy()) |
+ : AllocationPolicy::Deleter(allocator) { |
Initialize(0, allocator); |
} |
INLINE(explicit List(int capacity, |
- AllocationPolicy allocator = AllocationPolicy())) { |
+ AllocationPolicy allocator = AllocationPolicy())) |
+ : AllocationPolicy::Deleter(allocator) { |
Initialize(capacity, allocator); |
} |
INLINE(~List()) { DeleteData(data_); } |
@@ -71,7 +73,7 @@ class List { |
return allocator.New(static_cast<int>(size)); |
} |
INLINE(void operator delete(void* p)) { |
- AllocationPolicy::Delete(p); |
+ AllocationPolicy::Deleter::Delete(p); |
} |
// Please the MSVC compiler. We should never have to execute this. |
@@ -79,6 +81,13 @@ class List { |
UNREACHABLE(); |
} |
+ // Delete via the instance Deleter |
+ static void Delete(List* p) { |
+ if (p == NULL) return; |
+ p->~List(); |
+ p->AllocationPolicy::Deleter::Delete(p); |
+ } |
+ |
// Returns a reference to the element at index i. This reference is |
// not safe to use after operations that can change the list's |
// backing store (e.g. Add). |
@@ -179,7 +188,7 @@ class List { |
return static_cast<T*>(allocator.New(n * sizeof(T))); |
} |
INLINE(void DeleteData(T* data)) { |
- AllocationPolicy::Delete(data); |
+ this->AllocationPolicy::Deleter::Delete(data); |
} |
// Increase the capacity of a full list, and add an element. |