Repository: InsightSoftwareConsortium/ITK (language: python)

Issue:
Make the index type of VectorContainer `itk::SizeValueType` by default
For most use cases, it appears that the index type of `itk::VectorContainer` should just be `itk::SizeValueType` (or `itk::IdentifierType`, but that's just an alias of `itk::SizeValueType`).

This pull request allows users to write `itk::VectorContainer<ElementType>` as a shorthand for `itk::VectorContainer<itk::SizeValueType, ElementType>`.



Discussion / hints:

Fix patch:
diff --git a/Modules/Core/Common/include/itkDefaultStaticMeshTraits.h b/Modules/Core/Common/include/itkDefaultStaticMeshTraits.h
index e1359234aab..5f16c8b4b86 100644
--- a/Modules/Core/Common/include/itkDefaultStaticMeshTraits.h
+++ b/Modules/Core/Common/include/itkDefaultStaticMeshTraits.h
@@ -96,7 +96,7 @@ class ITK_TEMPLATE_EXPORT DefaultStaticMeshTraits
 
   /** The container type for use in storing points.  It must conform to
    * the IndexedContainer interface. */
-  using PointsContainer = VectorContainer<PointIdentifier, PointType>;
+  using PointsContainer = VectorContainer<PointType>;
 
   /** The container type that will be used to store boundary links
    * back to cells.  This must conform to the STL "set" interface. */
@@ -114,7 +114,7 @@ class ITK_TEMPLATE_EXPORT DefaultStaticMeshTraits
 
   /** The container type for use in storing cells.  It must conform to
    * the IndexedContainer interface. */
-  using CellsContainer = VectorContainer<CellIdentifier, CellType *>;
+  using CellsContainer = VectorContainer<CellType *>;
 
   /** The CellLinks container should be a container of PointCellLinksContainer,
    * which should be a container conforming to the STL "set" interface. */
@@ -122,15 +122,15 @@ class ITK_TEMPLATE_EXPORT DefaultStaticMeshTraits
 
   /** The container type for use in storing point links back to cells.
    * It must conform to the IndexedContainer interface. */
-  using CellLinksContainer = VectorContainer<PointIdentifier, PointCellLinksContainer>;
+  using CellLinksContainer = VectorContainer<PointCellLinksContainer>;
 
   /** The container type for use in storing point data.  It must conform to
    * the IndexedContainer interface. */
-  using PointDataContainer = VectorContainer<PointIdentifier, PixelType>;
+  using PointDataContainer = VectorContainer<PixelType>;
 
   /** The container type for use in storing cell data.  It must conform to
    * the IndexedContainer interface. */
-  using CellDataContainer = VectorContainer<CellIdentifier, CellPixelType>;
+  using CellDataContainer = VectorContainer<CellPixelType>;
 };
 } // end namespace itk
 
diff --git a/Modules/Core/Common/include/itkSTLContainerAdaptor.h b/Modules/Core/Common/include/itkSTLContainerAdaptor.h
index ce92df6a2bb..cc3ef0df6ab 100644
--- a/Modules/Core/Common/include/itkSTLContainerAdaptor.h
+++ b/Modules/Core/Common/include/itkSTLContainerAdaptor.h
@@ -32,7 +32,7 @@ namespace itk
  * Here's a usage example of STLContainerAdaptor:
  *
    \code
-       itk::STLContainerAdaptor<itk::VectorContainer<size_t, ElementType>> vecAdaptor(aContainer);
+       itk::STLContainerAdaptor<itk::VectorContainer<ElementType>> vecAdaptor(aContainer);
        std::vector<ElementType> & vec = vecAdaptor.GetSTLContainerRef();
        // do things with vec ...
        // upon return from function, vecAdaptor is destroyed and aContainer is Modified()
diff --git a/Modules/Filtering/FastMarching/include/itkFastMarchingTraits.h b/Modules/Filtering/FastMarching/include/itkFastMarchingTraits.h
index a0f61df8876..bf2308fde1f 100644
--- a/Modules/Filtering/FastMarching/include/itkFastMarchingTraits.h
+++ b/Modules/Filtering/FastMarching/include/itkFastMarchingTraits.h
@@ -66,7 +66,7 @@ class FastMarchingTraitsBase
   using NodePairContainerConstIterator = typename NodePairContainerType::ConstIterator;
 
   /*
-  using NodeContainerType = VectorContainer< IdentifierType, NodeType >;
+  using NodeContainerType = VectorContainer<NodeType>;
   using NodeContainerPointer = typename NodeContainerType::Pointer;
   using NodeContainerIterator = typename NodeContainerType::Iterator;
   using NodeContainerConstIterator = typename NodeContainerType::ConstIterator;


Test patch:
diff --git a/Modules/Core/Common/test/itkModifiedTimeTest.cxx b/Modules/Core/Common/test/itkModifiedTimeTest.cxx
index bdb3855502c..03871b36782 100644
--- a/Modules/Core/Common/test/itkModifiedTimeTest.cxx
+++ b/Modules/Core/Common/test/itkModifiedTimeTest.cxx
@@ -24,7 +24,7 @@ itkModifiedTimeTest(int, char *[])
 {
 
   using Point = itk::Point<double, 3>;
-  using PointsContainer = itk::VectorContainer<unsigned long, Point>;
+  using PointsContainer = itk::VectorContainer<Point>;
   using BoundingBox = itk::BoundingBox<unsigned long, 3, double, PointsContainer>;
 
   Point p, q, r;
diff --git a/Modules/Core/Common/test/itkPointGeometryTest.cxx b/Modules/Core/Common/test/itkPointGeometryTest.cxx
index 6208529ae0d..5c173564b94 100644
--- a/Modules/Core/Common/test/itkPointGeometryTest.cxx
+++ b/Modules/Core/Common/test/itkPointGeometryTest.cxx
@@ -265,7 +265,7 @@ itkPointGeometryTest(int, char *[])
     const double           tolerance = 1e-10;
     PointType              combination;
     constexpr unsigned int NP = 3;
-    using VectorOfPoints = itk::VectorContainer<unsigned long, PointType>;
+    using VectorOfPoints = itk::VectorContainer<PointType>;
     auto points = VectorOfPoints::New();
     points->Reserve(NP);
     constexpr double K = 12.0;
diff --git a/Modules/Core/Common/test/itkSTLContainerAdaptorTest.cxx b/Modules/Core/Common/test/itkSTLContainerAdaptorTest.cxx
index 72ebb1c262a..2773ba6a0ba 100644
--- a/Modules/Core/Common/test/itkSTLContainerAdaptorTest.cxx
+++ b/Modules/Core/Common/test/itkSTLContainerAdaptorTest.cxx
@@ -37,7 +37,7 @@ itkSTLContainerAdaptorTest(int, char *[])
 
     std::cout << "Testing the VectorContainer " << std::endl;
 
-    using VectorContainerType = itk::VectorContainer<IndexType, ElementType>;
+    using VectorContainerType = itk::VectorContainer<ElementType>;
 
     auto vectorContainer = VectorContainerType::New();
 
diff --git a/Modules/Core/Common/test/itkThreadedIteratorRangePartitionerTest2.cxx b/Modules/Core/Common/test/itkThreadedIteratorRangePartitionerTest2.cxx
index 3e09cb5515f..e7d989df893 100644
--- a/Modules/Core/Common/test/itkThreadedIteratorRangePartitionerTest2.cxx
+++ b/Modules/Core/Common/test/itkThreadedIteratorRangePartitionerTest2.cxx
@@ -27,7 +27,7 @@ class IteratorRangeDomainThreaderAssociate
 public:
   using Self = IteratorRangeDomainThreaderAssociate;
 
-  using DomainContainerType = itk::VectorContainer<unsigned int, int>;
+  using DomainContainerType = itk::VectorContainer<int>;
   using DomainContainerPointer = DomainContainerType::Pointer;
   using ThreadedPartitionerType = itk::ThreadedIteratorRangePartitioner<DomainContainerType::ConstIterator>;
 
diff --git a/Modules/Core/Common/test/itkVectorContainerGTest.cxx b/Modules/Core/Common/test/itkVectorContainerGTest.cxx
index 148219b5a9a..14599d35351 100644
--- a/Modules/Core/Common/test/itkVectorContainerGTest.cxx
+++ b/Modules/Core/Common/test/itkVectorContainerGTest.cxx
@@ -23,13 +23,10 @@
 #include <cstdlib>
 #include <string>
 
-// The tested ElementIdentifier type.
-using TestedElementIdentifierType = size_t;
-
 // Test template instantiations for various TElement template arguments:
-template class itk::detail::VectorContainer<TestedElementIdentifierType, int>;
-template class itk::detail::VectorContainer<TestedElementIdentifierType, bool>;
-template class itk::detail::VectorContainer<TestedElementIdentifierType, std::string>;
+template class itk::detail::VectorContainer<itk::SizeValueType, int>;
+template class itk::detail::VectorContainer<itk::SizeValueType, bool>;
+template class itk::detail::VectorContainer<itk::SizeValueType, std::string>;
 
 
 namespace
@@ -42,11 +39,11 @@ AssertSameType()
 }
 
 
-template <typename TElementIdentifier, typename TElement>
+template <typename TElement>
 constexpr bool
 AssertVectorContainerHasSamePublicNestedTypesAsStdVector()
 {
-  using VectorContainerType = itk::VectorContainer<TElementIdentifier, TElement>;
+  using VectorContainerType = itk::VectorContainer<TElement>;
   using StdVectorType = std::vector<TElement>;
 
   // Check the list of nested types of `std::vector` from section [vector.overview] of the C++ Standard Working Draft of
@@ -68,15 +65,15 @@ AssertVectorContainerHasSamePublicNestedTypesAsStdVector()
 }
 
 
-static_assert(AssertVectorContainerHasSamePublicNestedTypesAsStdVector<TestedElementIdentifierType, int>());
-static_assert(AssertVectorContainerHasSamePublicNestedTypesAsStdVector<TestedElementIdentifierType, bool>());
+static_assert(AssertVectorContainerHasSamePublicNestedTypesAsStdVector<int>());
+static_assert(AssertVectorContainerHasSamePublicNestedTypesAsStdVector<bool>());
 
 
-template <typename TElementIdentifier, typename TElement>
+template <typename TElement>
 void
-ExpectContainerHasValueOfCreatedElementAtIdentifier(const TElementIdentifier identifier, const TElement value)
+ExpectContainerHasValueOfCreatedElementAtIdentifier(const itk::SizeValueType identifier, const TElement value)
 {
-  const auto vectorContainer = itk::VectorContainer<TElementIdentifier, TElement>::New();
+  const auto vectorContainer = itk::VectorContainer<TElement>::New();
 
   vectorContainer->CreateElementAt(identifier) = value;
 
@@ -90,7 +87,7 @@ ExpectContainerHasValueOfCreatedElementAtIdentifier(const TElementIdentifier ide
 TEST(VectorContainer, HasValueOfCreatedElementAtIdentifier)
 {
   // Just pick a "pseudo-random" (magic) number as ElementIdentifier.
-  constexpr TestedElementIdentifierType magicIdentifier = 42;
+  constexpr itk::SizeValueType magicIdentifier = 42;
 
   ExpectContainerHasValueOfCreatedElementAtIdentifier(magicIdentifier, true);
   ExpectContainerHasValueOfCreatedElementAtIdentifier(magicIdentifier, false);
diff --git a/Modules/Core/Common/test/itkVectorContainerTest.cxx b/Modules/Core/Common/test/itkVectorContainerTest.cxx
index 5e24832a46c..ad34f5ebb42 100644
--- a/Modules/Core/Common/test/itkVectorContainerTest.cxx
+++ b/Modules/Core/Common/test/itkVectorContainerTest.cxx
@@ -19,7 +19,7 @@
 #include "itkVectorContainer.h"
 #include "itkTestingMacros.h"
 
-using ContainerType = itk::VectorContainer<size_t, double>;
+using ContainerType = itk::VectorContainer<double>;
 
 int
 itkVectorContainerTest(int, char *[])
diff --git a/Modules/Nonunit/IntegratedTest/test/itkCommonPrintTest.cxx b/Modules/Nonunit/IntegratedTest/test/itkCommonPrintTest.cxx
index 1764b169809..22d8affadb4 100644
--- a/Modules/Nonunit/IntegratedTest/test/itkCommonPrintTest.cxx
+++ b/Modules/Nonunit/IntegratedTest/test/itkCommonPrintTest.cxx
@@ -426,8 +426,7 @@ itkCommonPrintTest(int, char *[])
     itk::VarianceImageFunction<InputType, float>::New();
   std::cout << "------------VarianceImageFunction" << VarianceImageFunctionObj;
 
-  itk::VectorContainer<unsigned long, PointType>::Pointer VectorContainerObj =
-    itk::VectorContainer<unsigned long, PointType>::New();
+  itk::VectorContainer<PointType>::Pointer VectorContainerObj = itk::VectorContainer<PointType>::New();
   std::cout << "------------VectorContainer" << VectorContainerObj;
 
   itk::VectorImage<float, 3>::Pointer VectorImageObj = itk::VectorImage<float, 3>::New();
diff --git a/Modules/Numerics/Statistics/test/itkVectorContainerToListSampleAdaptorTest.cxx b/Modules/Numerics/Statistics/test/itkVectorContainerToListSampleAdaptorTest.cxx
index 7d69244ef70..8296159a4b3 100644
--- a/Modules/Numerics/Statistics/test/itkVectorContainerToListSampleAdaptorTest.cxx
+++ b/Modules/Numerics/Statistics/test/itkVectorContainerToListSampleAdaptorTest.cxx
@@ -25,7 +25,7 @@ itkVectorContainerToListSampleAdaptorTest(int, char *[])
 
   using VectorType = itk::Vector<double, 5>;
 
-  using ContainerType = itk::VectorContainer<unsigned int, VectorType>;
+  using ContainerType = itk::VectorContainer<VectorType>;
 
   using AdaptorType = itk::Statistics::VectorContainerToListSampleAdaptor<ContainerType>;
 
diff --git a/Modules/Registration/Common/test/itkPointsLocatorTest.cxx b/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
index 5d85da3cc80..746c5626560 100644
--- a/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
+++ b/Modules/Registration/Common/test/itkPointsLocatorTest.cxx
@@ -138,7 +138,7 @@ itkPointsLocatorTest(int, char *[])
   constexpr unsigned int PointDimension = 3;
   using PointType = itk::Point<float, PointDimension>;
 
-  using VectorContainerType = itk::VectorContainer<unsigned int, PointType>;
+  using VectorContainerType = itk::VectorContainer<PointType>;
   using MapContainerType = itk::MapContainer<unsigned int, PointType>;
 
   std::cout << "VectorContainerType" << std::endl;