diff options
Diffstat (limited to 'Common/interface')
| -rw-r--r-- | Common/interface/STDAllocator.h | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/Common/interface/STDAllocator.h b/Common/interface/STDAllocator.h index cf2290be..10f6769a 100644 --- a/Common/interface/STDAllocator.h +++ b/Common/interface/STDAllocator.h @@ -158,17 +158,37 @@ template<class T> using STDAllocatorRawMem = STDAllocator<T, IMemoryAllocator>; template< class T, typename AllocatorType > struct STDDeleter { - STDDeleter(AllocatorType &Allocator) : - m_Allocator(Allocator) + STDDeleter() noexcept {} + + STDDeleter(AllocatorType& Allocator) noexcept : + m_Allocator(&Allocator) {} - - void operator()(T *ptr) + + STDDeleter (const STDDeleter&) = default; + STDDeleter& operator = (const STDDeleter&) = default; + + STDDeleter(STDDeleter&& rhs) noexcept : + m_Allocator(rhs.m_Allocator) + { + rhs.m_Allocator = nullptr; + } + + STDDeleter& operator = (STDDeleter&& rhs) noexcept { + m_Allocator = rhs.m_Allocator; + rhs.m_Allocator = nullptr; + return *this; + } + + void operator()(T *ptr) noexcept + { + VERIFY(m_Allocator != nullptr, "The deleter has been moved away or never initialized, and can't be used"); ptr->~T(); - m_Allocator.Free(ptr); + m_Allocator->Free(ptr); } - AllocatorType &m_Allocator; +private: + AllocatorType* m_Allocator = nullptr; }; template<class T> using STDDeleterRawMem = STDDeleter<T, IMemoryAllocator>; |
