Skip to content

Add constexpr to if when comparing dimensions, remove a few unnecessary static_cast's#5320

Merged
hjmjohnson merged 3 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Dimension-style
Apr 23, 2025
Merged

Add constexpr to if when comparing dimensions, remove a few unnecessary static_cast's#5320
hjmjohnson merged 3 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Dimension-style

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

A few style commits, using the fact that dimensions are defined as constexpr unsigned int.

Dimensions are already `unsigned int`, so these casts had no effect anyway.

Replaced `static_cast<unsigned int>\(([A-Za-z]+Dimension)\)` with `$1`, using
regular expressions.

Replaced `static_cast<unsigned int>(Self::CellDimension)` with `CellDimension`.
When comparing one dimension with another, it is unnecessary to cast the two
operands to `int`.
In ITK, the dimensions are typically known at compile-time.
@github-actions github-actions bot added type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Segmentation Issues affecting the Segmentation module area:Numerics Issues affecting the Numerics module labels Apr 23, 2025
@N-Dekker N-Dekker marked this pull request as ready for review April 23, 2025 13:22
Comment on lines -60 to -63
if (inputPtr != nullptr &&
static_cast<unsigned int>(InputImageDimension) == static_cast<unsigned int>(OutputImageDimension))
if (inputPtr != nullptr && InputImageDimension == OutputImageDimension)
{
for (unsigned int i = 0; i < static_cast<unsigned int>(InputImageDimension); ++i)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those static_cast<unsigned int>'s may look a bit silly nowadays, because a dimension is already unsigned int, but I think they were still meaningful for ITK 4, before C++11, when dimensions were represented by enum constants.

Copy link
Copy Markdown
Member

@hjmjohnson hjmjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@hjmjohnson hjmjohnson merged commit a674142 into InsightSoftwareConsortium:master Apr 23, 2025
16 checks passed
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request May 6, 2025
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Numerics Issues affecting the Numerics module area:Segmentation Issues affecting the Segmentation module type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants