From 4b5e5bea934d2540c8f0013dff889d1b812b3bd9 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 26 Sep 2024 23:14:05 +0200 Subject: [PATCH] ENH: Make index type of VectorContainer SizeValueType by default By default, assume `ElementIdentifier = SizeValueType`, for an `itk::VectorContainer`. Conceptually like: template class VectorContainer; Implemented by moving the old `VectorContainer` definition into the `itk::detail` namespace, and introducing a new `itk::VectorContainer` alias template. --- .../Core/Common/include/itkVectorContainer.h | 19 +++++++++++++++++++ .../Common/include/itkVectorContainer.hxx | 4 ++-- .../Common/test/itkVectorContainerGTest.cxx | 6 +++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Modules/Core/Common/include/itkVectorContainer.h b/Modules/Core/Common/include/itkVectorContainer.h index e32462d8458..56447a4ac45 100644 --- a/Modules/Core/Common/include/itkVectorContainer.h +++ b/Modules/Core/Common/include/itkVectorContainer.h @@ -21,11 +21,14 @@ #include "itkObject.h" #include "itkObjectFactory.h" +#include // For is_void_v. #include #include namespace itk { +namespace detail +{ /** \class VectorContainer * \brief Define a front-end to the STL "vector" container that conforms to the * IndexedContainerInterface. @@ -561,6 +564,22 @@ class ITK_TEMPLATE_EXPORT VectorContainer , VectorType(first, last) {} }; +} // namespace detail + + +/** Alias template, allowing to use `itk::VectorContainer` without having to explicitly specify its + * `ElementIdentifier` type. + * + * The template parameters `T1` and `T2` allow specifying the index type and the element type, as follows: + * + * \tparam T1 The index type OR (when `T2` is `void`) the element type. + * + * \tparam T2 The element type OR `void`. When `T2` is `void`, the element type is specified by the first template + * argument (T1), and the index type will be `SizeValueType`. + */ +template +using VectorContainer = detail::VectorContainer, SizeValueType, T1>, + std::conditional_t, T1, T2>>; /** Makes a VectorContainer that has a copy of the specified `std::vector`. */ diff --git a/Modules/Core/Common/include/itkVectorContainer.hxx b/Modules/Core/Common/include/itkVectorContainer.hxx index 6a658639036..a8fc5962093 100644 --- a/Modules/Core/Common/include/itkVectorContainer.hxx +++ b/Modules/Core/Common/include/itkVectorContainer.hxx @@ -20,7 +20,7 @@ #include "itkNumericTraits.h" -namespace itk +namespace itk::detail { template @@ -183,6 +183,6 @@ template void VectorContainer::Squeeze() {} -} // end namespace itk +} // namespace itk::detail #endif diff --git a/Modules/Core/Common/test/itkVectorContainerGTest.cxx b/Modules/Core/Common/test/itkVectorContainerGTest.cxx index 90b311b728c..148219b5a9a 100644 --- a/Modules/Core/Common/test/itkVectorContainerGTest.cxx +++ b/Modules/Core/Common/test/itkVectorContainerGTest.cxx @@ -27,9 +27,9 @@ using TestedElementIdentifierType = size_t; // Test template instantiations for various TElement template arguments: -template class itk::VectorContainer; -template class itk::VectorContainer; -template class itk::VectorContainer; +template class itk::detail::VectorContainer; +template class itk::detail::VectorContainer; +template class itk::detail::VectorContainer; namespace