Skip to content

Remove local type aliases of Image Iterators in *.hxx, use CTAD#5989

Merged
hjmjohnson merged 3 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Remove-local-type-aliases-Image-Iterators
Mar 30, 2026
Merged

Remove local type aliases of Image Iterators in *.hxx, use CTAD#5989
hjmjohnson merged 3 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Remove-local-type-aliases-Image-Iterators

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

Using Notepad++, Replace in Files, doing:

Find what: ^[ ]+ using (\w+) = (Image\w+Iterator<\w+>);\r\n(.*?[^\w])\1
Filters: itk*.hxx
[v] Match case
(*) Regular expression
[v] . matches newline

Followed by manual replacements of uses of those type aliases.

@github-actions github-actions bot added area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module type:Style Style changes: no logic impact (indentation, comments, naming) labels Mar 29, 2026
Using Notepad++, Replace in Files, doing:

    Find what: ^[ ]+ using (\w+) = (Image\w+Iterator<\w+>);\r\n(.*?[^\w])\1
    Filters: itk*.hxx
    [v] Match case
    (*) Regular expression
    [v] . matches newline

Followed by manual replacements of uses of those type aliases.

Follow-up to pull request InsightSoftwareConsortium#5981
commit 901ea16
"STYLE: Remove local type aliases of ImageRegionConstIterator in `*.hxx`"
@N-Dekker N-Dekker force-pushed the Remove-local-type-aliases-Image-Iterators branch from c686d41 to 6ee4c37 Compare March 29, 2026 14:18
Used class template argument deduction (CTAD) when declaring variables of an
Image Iterator type.

Using Notepad++, Replace in Files, doing:

    Find what: ([^\w]Image\w+Iterator)<.+>[ ]*( \w+[\({])
    Replace with: $1$2
    Files: itk*.hxx
    [v] Match case
    (*) Regular expression

Follow-up to pull request InsightSoftwareConsortium#5982
commit b6a38b1
"STYLE: Use CTAD for `ImageRegionIterator` variables in hxx files"
Used class template argument deduction (CTAD) when assigning a temporary Image
Iterator.

Using Notepad++, Replace in Files, doing:

    Find what: ( = Image\w+Iterator)<\w+>([\({])
    Replace with: $1$2
    Files: itk*.hxx
    [v] Match case
    (*) Regular expression

Follow-up to pull request InsightSoftwareConsortium#5982
commit b6a38b1
"STYLE: Use CTAD for `ImageRegionIterator` variables in hxx files"
@github-actions github-actions bot added area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module labels Mar 29, 2026
@N-Dekker N-Dekker changed the title STYLE: Remove local type aliases of Image Iterators in *.hxx Remove local type aliases of Image Iterators in *.hxx, use CTAD Mar 29, 2026
@N-Dekker N-Dekker marked this pull request as ready for review March 30, 2026 12:09
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This is a pure C++17 modernization PR that removes redundant local type aliases (e.g., using IteratorType = ImageRegionIterator<OutputImageType>) across 29 .hxx implementation files and replaces their uses with either the full explicit type or CTAD (Class Template Argument Deduction) where the template argument can be deduced from the constructor's image-pointer argument. No logic or algorithmic changes are made.

Key patterns applied:

  • using IteratorType = SomeIterator<T>; ... IteratorType var(img, region)SomeIterator var(img, region) (CTAD)
  • In contexts where CTAD cannot be used (C-array declarations, make_unique_for_overwrite<T[]>, std::vector<T*>, typename std::vector<T*>::iterator), the full explicit type SomeIterator<T> is kept — handled correctly throughout.
  • Assignment to a pre-declared variable with an explicit type (e.g., ImageRegionIterator<TOutputImage> it = ImageRegionIterator(...)) is valid because the CTAD-deduced type on the RHS matches the declared type on the LHS.

Notable files:

  • itkSTAPLEImageFilter.hxx: Both IteratorType and FuzzyIteratorType aliases removed; make_unique_for_overwrite call correctly expands to the full ImageScanlineConstIterator<TInputImage>[] since CTAD is not applicable to template arguments.
  • itkBSplineDeformableTransform.hxx / itkBSplineTransform.hxx: C-array declaration retains the explicit <ImageType> (necessary because there is no initializer from which to deduce), while the loop assignment correctly uses CTAD.
  • itkNaryFunctorImageFilter.hxx: Vector-of-pointer and new expressions retain explicit template arguments — correct, as CTAD cannot appear in template-argument position.

Confidence Score: 5/5

Safe to merge — purely mechanical modernization with no functional changes and no new logic introduced.

All changes are cosmetic C++17 CTAD clean-ups; every CTAD use deduces the same type that was previously spelled out explicitly, and every location where CTAD cannot apply correctly retains the explicit template argument. No bugs, no regressions, no logic alterations found across all 29 files.

No files require special attention.

Important Files Changed

Filename Overview
Modules/Core/Common/include/itkImageAlgorithm.hxx Removes explicit template arguments from ImageScanlineConstIterator and ImageScanlineIterator using CTAD; straightforward cleanup.
Modules/Core/Transform/include/itkBSplineDeformableTransform.hxx Removes using IteratorType alias; array declaration keeps explicit (required for C-arrays), CTAD used only in the assignment inside the loop.
Modules/Core/Transform/include/itkBSplineTransform.hxx Identical pattern to itkBSplineDeformableTransform.hxx; alias removed, C-array retains explicit type, loop assignment uses CTAD.
Modules/Filtering/ImageCompare/include/itkSTAPLEImageFilter.hxx Removes IteratorType/FuzzyIteratorType aliases; make_unique_for_overwrite call correctly expands to the full explicit type ImageScanlineConstIterator[] since CTAD cannot apply there.
Modules/Filtering/ImageIntensity/include/itkNaryFunctorImageFilter.hxx Removes ImageScanlineConstIteratorType alias; explicit template argument retained in vector-of-pointer and new expressions where CTAD cannot be used; memory ownership via manual delete is pre-existing.
Modules/Filtering/ImageFeature/include/itkZeroCrossingImageFilter.hxx Right-hand side switches to CTAD while the declared type keeps explicit ; the deduced type matches, so this compiles correctly and is functionally equivalent.
Modules/Filtering/Smoothing/include/itkBinomialBlurImageFilter.hxx Removes TempReverseIterator alias; ImageRegionReverseIterator variable declaration uses CTAD directly, which is cleaner.
Modules/Registration/PDEDeformable/include/itkCurvatureRegistrationFilter.hxx CTAD applied to ImageRegionConstIterator and ImageRegionIterator assignments; ImageRegionConstIteratorWithIndex retains explicit type (not changed in this PR).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Local alias present\n(using IteratorType = SomeIterator<T>)"]
    A -->|"alias used only as constructor\n(IteratorType it(img, region))"| B["Remove alias\nUse CTAD: SomeIterator it(img, region)"]
    A -->|"alias used in assignment RHS\n(it = IteratorType(img, region))"| C["Remove alias\nUse CTAD on RHS: it = SomeIterator(img, region)"]
    A -->|"alias used in C-array declaration\n(IteratorType arr[N])"| D["Remove alias\nKeep explicit type: SomeIterator<T> arr[N]"]
    A -->|"alias used as template arg\n(vector<IteratorType*>, make_unique<IteratorType[]>)"| E["Remove alias\nKeep explicit type: SomeIterator<T> in template arg"]
    B --> F["CTAD deduces T from image ptr"]
    C --> F
    D --> G["Explicit type required\n(no initializer for deduction)"]
    E --> G
Loading

Reviews (1): Last reviewed commit: "STYLE: Use CTAD when assigning an Image ..." | Re-trigger Greptile

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.

Thanks.

Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

Do all iterator types have CTAD guides? Code is both less verbose and more readable when using them. We should have them and apply them for all the iterator types. Perhaps something to consider in follow-up PR(s)?

@N-Dekker
Copy link
Copy Markdown
Contributor Author

Do all iterator types have CTAD guides? Code is both less verbose and more readable when using them. We should have them and apply them for all the iterator types. Perhaps something to consider in follow-up PR(s)?

The Image Iterators all have a CTAD guide for ImageIteratorType(image, region). As tested here:

CheckIteratorsSupportClassTemplateArgumentDeduction<itk::ImageConstIterator,
itk::ImageConstIteratorWithIndex,
itk::ImageConstIteratorWithOnlyIndex,
itk::ImageIterator,
itk::ImageIteratorWithIndex,
itk::ImageLinearConstIteratorWithIndex,
itk::ImageLinearIteratorWithIndex,
itk::ImageRandomConstIteratorWithIndex,
itk::ImageRandomConstIteratorWithOnlyIndex,
itk::ImageRandomIteratorWithIndex,
itk::ImageRandomNonRepeatingConstIteratorWithIndex,
itk::ImageRandomNonRepeatingIteratorWithIndex,
itk::ImageRegionConstIterator,
itk::ImageRegionConstIteratorWithIndex,
itk::ImageRegionConstIteratorWithOnlyIndex,
itk::ImageRegionExclusionConstIteratorWithIndex,
itk::ImageRegionExclusionIteratorWithIndex,
itk::ImageRegionIterator,
itk::ImageRegionIteratorWithIndex,
itk::ImageRegionReverseConstIterator,
itk::ImageRegionReverseIterator,
itk::ImageReverseConstIterator,
itk::ImageReverseIterator,
itk::ImageScanlineConstIterator,
itk::ImageScanlineIterator,
itk::ImageSliceConstIteratorWithIndex,
itk::ImageSliceIteratorWithIndex>();

@hjmjohnson hjmjohnson merged commit 151d64f into InsightSoftwareConsortium:main Mar 30, 2026
19 checks passed
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:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants