Remove local type aliases of Image Iterators in *.hxx, use CTAD#5989
Conversation
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`"
c686d41 to
6ee4c37
Compare
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"
*.hxx*.hxx, use CTAD
|
| 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
Reviews (1): Last reviewed commit: "STYLE: Use CTAD when assigning an Image ..." | Re-trigger Greptile
dzenanz
left a comment
There was a problem hiding this comment.
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 ITK/Modules/Core/Common/test/itkImageIteratorsGTest.cxx Lines 187 to 213 in 8fcd691 |
Using Notepad++, Replace in Files, doing:
Followed by manual replacements of uses of those type aliases.
*.hxxfiles #5981