From 824b041b212d977da83187e4a06c8037789ba48a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 21 Sep 2023 14:12:22 +0200 Subject: [PATCH] STYLE: Default constructors VectorContainer, Iterator, ConstIterator Defaulted the default-constructors of `VectorContainer`, `VectorContainer::Iterator`, and `VectorContainer::ConstIterator`. Added in-class default member initializers to their member variables. Added `[[maybe_unused]]` attributes to itkVectorContainerTest, to avoid Clang warnings ("unused variable 'p_null' [-Wunused-variable]") which would otherwise appear when defaulting those default-constructors. --- .../Core/Common/include/itkVectorContainer.h | 21 +++++++------------ .../Common/test/itkVectorContainerTest.cxx | 16 +++++++------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Modules/Core/Common/include/itkVectorContainer.h b/Modules/Core/Common/include/itkVectorContainer.h index fa35193be77..315d2578efa 100644 --- a/Modules/Core/Common/include/itkVectorContainer.h +++ b/Modules/Core/Common/include/itkVectorContainer.h @@ -71,10 +71,7 @@ class ITK_TEMPLATE_EXPORT VectorContainer /** Provide pass-through constructors corresponding to all the STL * vector constructors. These are for internal use only since this is also * an Object which must be constructed through the "New()" routine. */ - VectorContainer() - : Object() - , VectorType() - {} + VectorContainer() = default; VectorContainer(size_type n) : Object() , VectorType(n) @@ -185,9 +182,7 @@ class ITK_TEMPLATE_EXPORT VectorContainer using pointer = typename VectorIterator::pointer; using reference = typename VectorIterator::reference; - Iterator() - : m_Pos(0) - {} + Iterator() = default; Iterator(size_type d, const VectorIterator & i) : m_Pos(d) , m_Iter(i) @@ -292,8 +287,8 @@ class ITK_TEMPLATE_EXPORT VectorContainer } private: - size_type m_Pos; - VectorIterator m_Iter; + size_type m_Pos{}; + VectorIterator m_Iter{}; friend class ConstIterator; }; @@ -311,9 +306,7 @@ class ITK_TEMPLATE_EXPORT VectorContainer using pointer = typename VectorConstIterator::pointer; using reference = typename VectorConstIterator::reference; - ConstIterator() - : m_Pos(0) - {} + ConstIterator() = default; ConstIterator(size_type d, const VectorConstIterator & i) : m_Pos(d) , m_Iter(i) @@ -428,8 +421,8 @@ class ITK_TEMPLATE_EXPORT VectorContainer } private: - size_type m_Pos; - VectorConstIterator m_Iter; + size_type m_Pos{}; + VectorConstIterator m_Iter{}; friend class Iterator; }; diff --git a/Modules/Core/Common/test/itkVectorContainerTest.cxx b/Modules/Core/Common/test/itkVectorContainerTest.cxx index 1b4e80fd758..5e24832a46c 100644 --- a/Modules/Core/Common/test/itkVectorContainerTest.cxx +++ b/Modules/Core/Common/test/itkVectorContainerTest.cxx @@ -33,10 +33,10 @@ itkVectorContainerTest(int, char *[]) // Iterator { - ContainerType::Iterator p_null; - ContainerType::Iterator p = container->Begin(); - ContainerType::Iterator p_copy(p); - ContainerType::Iterator p_assign = p; + [[maybe_unused]] ContainerType::Iterator p_null; + ContainerType::Iterator p = container->Begin(); + ContainerType::Iterator p_copy(p); + ContainerType::Iterator p_assign = p; while (p != container->End()) { @@ -51,10 +51,10 @@ itkVectorContainerTest(int, char *[]) // ConstIterator { - ContainerType::ConstIterator p_null; - ContainerType::ConstIterator p = container->Begin(); - ContainerType::ConstIterator p_copy(p); - ContainerType::ConstIterator p_assign = p; + [[maybe_unused]] ContainerType::ConstIterator p_null; + ContainerType::ConstIterator p = container->Begin(); + ContainerType::ConstIterator p_copy(p); + ContainerType::ConstIterator p_assign = p; while (p != container->End()) {