From d720117d367a5025b75f8c87411e4338b852b8e4 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 3 Dec 2025 18:08:38 +0100 Subject: [PATCH] STYLE: Make `NumericTraits::GetLength` constexpr whenever possible It appears that most `NumericTraits` specializations can have constexpr `GetLength` member functions. The only `NumericTraits` specializations whose `GetLength` member functions cannot be constexpr are for `std::vector` and `VariableLengthVector` --- Modules/Core/Common/include/itkNumericTraits.h | 4 ++-- .../Common/include/itkNumericTraitsCovariantVectorPixel.h | 4 ++-- .../Common/include/itkNumericTraitsDiffusionTensor3DPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsPointPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsRGBAPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsRGBPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsTensorPixel.h | 4 ++-- Modules/Core/Common/include/itkNumericTraitsVectorPixel.h | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Modules/Core/Common/include/itkNumericTraits.h b/Modules/Core/Common/include/itkNumericTraits.h index 65dcdaf3f7a..16ce69396e2 100644 --- a/Modules/Core/Common/include/itkNumericTraits.h +++ b/Modules/Core/Common/include/itkNumericTraits.h @@ -198,14 +198,14 @@ class NumericTraits : public std::numeric_limits * VariableLengthVector will provide a different implementation * where a vector of the correct size is built. */ - static unsigned int + static constexpr unsigned int GetLength(const T &) { return GetLength(); } /** Return the length of the scalar: 1. Array types can return a different value */ - static unsigned int + static constexpr unsigned int GetLength() { return 1; diff --git a/Modules/Core/Common/include/itkNumericTraitsCovariantVectorPixel.h b/Modules/Core/Common/include/itkNumericTraitsCovariantVectorPixel.h index 95bff64b64f..581a5745446 100644 --- a/Modules/Core/Common/include/itkNumericTraitsCovariantVectorPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsCovariantVectorPixel.h @@ -161,14 +161,14 @@ class NumericTraits> } /** Return the length of the vector. */ - static unsigned int + static constexpr unsigned int GetLength(const CovariantVector &) { return D; } /** Return the length of the vector. */ - static unsigned int + static constexpr unsigned int GetLength() { return D; diff --git a/Modules/Core/Common/include/itkNumericTraitsDiffusionTensor3DPixel.h b/Modules/Core/Common/include/itkNumericTraitsDiffusionTensor3DPixel.h index 0956137270f..809c41aaec0 100644 --- a/Modules/Core/Common/include/itkNumericTraitsDiffusionTensor3DPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsDiffusionTensor3DPixel.h @@ -163,14 +163,14 @@ class NumericTraits> } /** Return the size of the tensor. Always returns 6. */ - static unsigned int + static constexpr unsigned int GetLength(const DiffusionTensor3D &) { return 6; } /** Return the size of the tensor. Always returns 6. */ - static unsigned int + static constexpr unsigned int GetLength() { return 6; diff --git a/Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h b/Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h index 3e5ec2590e1..0b2843c0100 100644 --- a/Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsFixedArrayPixel.h @@ -157,14 +157,14 @@ class NumericTraits> } /** Return the length of the array. */ - static unsigned int + static constexpr unsigned int GetLength(const FixedArray &) { return D; } /** Return the length of the array. */ - static unsigned int + static constexpr unsigned int GetLength() { return D; diff --git a/Modules/Core/Common/include/itkNumericTraitsPointPixel.h b/Modules/Core/Common/include/itkNumericTraitsPointPixel.h index 53b2217f87f..08eb781e56a 100644 --- a/Modules/Core/Common/include/itkNumericTraitsPointPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsPointPixel.h @@ -148,14 +148,14 @@ class NumericTraits> } /** Return the dimensionality of the point. */ - static unsigned int + static constexpr unsigned int GetLength(const Point &) { return D; } /** Return the dimensionality of the point. */ - static unsigned int + static constexpr unsigned int GetLength() { return D; diff --git a/Modules/Core/Common/include/itkNumericTraitsRGBAPixel.h b/Modules/Core/Common/include/itkNumericTraitsRGBAPixel.h index 196cd03c143..422a5da8831 100644 --- a/Modules/Core/Common/include/itkNumericTraitsRGBAPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsRGBAPixel.h @@ -188,14 +188,14 @@ class NumericTraits> } /** Return the dimensionality of the pixel. Always returns 4. */ - static unsigned int + static constexpr unsigned int GetLength(const RGBAPixel &) { return 4; } /** Return the dimensionality of the pixel. Always returns 4. */ - static unsigned int + static constexpr unsigned int GetLength() { return 4; diff --git a/Modules/Core/Common/include/itkNumericTraitsRGBPixel.h b/Modules/Core/Common/include/itkNumericTraitsRGBPixel.h index ff4321f8fc5..4a5884415ce 100644 --- a/Modules/Core/Common/include/itkNumericTraitsRGBPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsRGBPixel.h @@ -188,14 +188,14 @@ class NumericTraits> } /** Return the dimensionality of the pixel. Always returns 3. */ - static unsigned int + static constexpr unsigned int GetLength(const RGBPixel &) { return 3; } /** Return the dimensionality of the pixel. Always returns 3. */ - static unsigned int + static constexpr unsigned int GetLength() { return 3; diff --git a/Modules/Core/Common/include/itkNumericTraitsTensorPixel.h b/Modules/Core/Common/include/itkNumericTraitsTensorPixel.h index 57eb4be881d..6251d0c19f3 100644 --- a/Modules/Core/Common/include/itkNumericTraitsTensorPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsTensorPixel.h @@ -163,14 +163,14 @@ class NumericTraits> } /** Return the size of the underlying FixedArray. */ - static unsigned int + static constexpr unsigned int GetLength(const SymmetricSecondRankTensor &) { return GetLength(); } /** Return the size of the underlying FixedArray. */ - static unsigned int + static constexpr unsigned int GetLength() { return D * (D + 1) / 2; diff --git a/Modules/Core/Common/include/itkNumericTraitsVectorPixel.h b/Modules/Core/Common/include/itkNumericTraitsVectorPixel.h index b705717e0d3..4491be35c0c 100644 --- a/Modules/Core/Common/include/itkNumericTraitsVectorPixel.h +++ b/Modules/Core/Common/include/itkNumericTraitsVectorPixel.h @@ -203,14 +203,14 @@ class NumericTraits> } /** Return the size of the vector. */ - static unsigned int + static constexpr unsigned int GetLength(const Vector &) { return D; } /** Return the size of the vector. */ - static unsigned int + static constexpr unsigned int GetLength() { return D;