From e279a06d33566b5936a54317cf1e02313267f757 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 21 Mar 2023 13:31:26 +0100 Subject: [PATCH] STYLE: Remove std::allocator from TestImportImageContainer (Common/test) Replaced the use of `std::allocator` by the equivalent `new Element[]` and `delete[]` statements. Renamed `m_MemoryAllocatedByAllocator` to `m_MemoryAllocatedByTestImportImageContainer`. Aims to simplify the code, and make it easier to upgrade to C++17 and further. C++17 has deprecated the `std::allocator::allocate` and `std::allocator::destroy` function calls that are removed with this commit. --- .../Core/Common/test/itkFactoryTestLib.cxx | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/Modules/Core/Common/test/itkFactoryTestLib.cxx b/Modules/Core/Common/test/itkFactoryTestLib.cxx index e161e535852..eea9007cbbe 100644 --- a/Modules/Core/Common/test/itkFactoryTestLib.cxx +++ b/Modules/Core/Common/test/itkFactoryTestLib.cxx @@ -43,8 +43,6 @@ class TestImportImageContainer : public itk::ImportImageContainer; - // Methods from itkObject virtual ~TestImportImageContainer() { @@ -67,21 +65,9 @@ class TestImportImageContainer : public itk::ImportImageContainer(m_Allocator.allocate(size, 0)); - if (data) - { - new (data) Element[size]; - } + data = new Element[size]; } catch (...) - { - data = 0; - } - if (!data) { // We cannot construct an error string here because we may be out // of memory. Do not use the exception macro. @@ -91,7 +77,7 @@ class TestImportImageContainer : public itk::ImportImageContainerCapacity() << " bytes" << std::endl; - if (m_MemoryAllocatedByAllocator) + if (m_MemoryAllocatedByTestImportImageContainer) { - TElement * ptr = this->GetImportPointer(); - const TElement * const end = ptr + this->Capacity(); - for (TElement * base = ptr; base < end; ++base) - { - m_Allocator.destroy(base); - } - m_Allocator.deallocate(ptr, this->Capacity()); - + delete[] this->GetImportPointer(); this->SetImportPointer(0); this->SetCapacity(0); this->SetSize(0); @@ -130,8 +109,7 @@ class TestImportImageContainer : public itk::ImportImageContainer