Skip to content

STYLE: Move code only, for #7065 - #7117

Closed
dzenanz wants to merge 20 commits into
InsightSoftwareConsortium:mainfrom
dzenanz:pr7065-split
Closed

dzenanz wants to merge 20 commits into
InsightSoftwareConsortium:mainfrom
dzenanz:pr7065-split

Conversation

@dzenanz

@dzenanz dzenanz commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

This is a temporary PR, to help review the changes in #7065.

mymonin and others added 20 commits November 4, 2026 17:05
…rator"

Lines rearranged verbatim from a6ccc9d; the next commit edits in place.
The original inheritance-based design of the iterator class pairs has several
problems, notably the pervasive need to const_cast away the pointer-to-const
member whenever an iterator needs write access. This opens up opportunities
for accidental or deliberate const-correctness violation.

This refactor makes itk::ImageIterator a standalone template class that
models both read-only and read/write access semantics based solely on the
constness of the template type.

ImageConstIterator<T> then functionally acts as an alias template for
ImageIterator<const T>. It is implemented as a minimal derived class due to
CTAD not being available for alias templates pre-C++20.
ImageIterator<const T> converted only from ImageIterator<T>, so the
documented equivalence with ImageConstIterator<T> held one way, and
the comparison operators accepted iterators over unrelated images.
One trait now states the allowed conversion (same image, never
dropping const) for all iterators; comparisons require the same image.

C++20 compilers use requires-clauses and operator<=>, and C++26
compilers name the forbidden read-only to writable conversion.
… image constness"

Lines rearranged verbatim from ec2f839; the next commit edits in place.
ImageRegionIterator<T> inherited from ImageRegionConstIterator<T> and
cast away const to write, so ImageRegionIterator<const T> could write
to a const image (InsightSoftwareConsortium#7003). ImageRegionIterator now derives from
ImageIterator<T> and writes only when T is not const;
ImageRegionConstIterator<T> is ImageRegionIterator<const T>, with
deduction guides for smart and raw pointers. Both headers provide
both classes.
…by image constness"

Lines rearranged verbatim from a5a675c; the next commit edits in place.
Apply the ImageRegionIterator design to the scanline pair, so
ImageScanlineIterator<const T> cannot write and the const_cast in
Set() and Value() goes away.
…age constness"

Lines rearranged verbatim from 0daca48; the next commit edits in place.
ImageReverseConstIterator offered a public Set() that cast away const,
and the writable reverse iterators accepted read-only sources. The
four reverse classes now share ImageRegionReverseIterator<T>, writable
only when T is not const; the other names derive from it, so every
existing method remains except writes through a const image.

Conversion from a forward iterator now sets the row span from the
current position; before, the span end was computed from a span begin
that was not yet set. The GetBufferPointer test now converts from a
writable iterator, since conversion from a read-only one is removed.
… by image constness"

Lines rearranged verbatim from a9611d9; the next commit edits in place.
Apply the ImageIterator design to the root of the WithIndex family:
ImageIteratorWithIndex<T> holds the position as a pointer to const
pixels only when T is const, so Set() and Value() need no const_cast
and are absent for const images. ImageConstIteratorWithIndex<T> is
ImageIteratorWithIndex<const T>.
…image constness"

Lines rearranged verbatim from f748995; the next commit edits in place.
Apply the ImageIteratorWithIndex design to the region, linear, slice,
random, random non-repeating, and region exclusion iterators. Each
XxxIteratorWithIndex<T> derives from its writable base, inherits the
constness-gated Set() and Value(), and XxxConstIteratorWithIndex<T>
is XxxIteratorWithIndex<const T>. The random non-repeating conversion
deep-copies the permutation it owns.
…ator access by constness"

Lines rearranged verbatim from 2d24382; the next commit edits in place.
The frequency-layout iterators and ReflectiveImageRegionIterator
inherited from read-only bases and cast away const to write. They now
derive from the writable WithIndex iterators, so writes need no cast
and are unavailable for const images; each Const name is the iterator
over the const image.
… access by image constness"

Lines rearranged verbatim from c056797; the next commit edits in place.
LineIterator and PathIterator wrote through a const_cast of the
const image held by their read-only bases. Each is now the iterator,
writable only when TImage is not const, and the Const name iterates
over the const image. PathIterator::Value() read a nonexistent
member, so it could not compile; it now returns the current pixel.
The writable flood-filled iterators cast away the const image held by
ConditionalConstIterator to write a pixel. They now keep the writable
image pointer their constructor receives, offer Set() only for
non-const images, and read through the const image without a cast.
Adds compile-time checks that the indexed iterators keep the ITK 5
ImageIteratorDimension constant, that the exclusion iterator can be built
from a plain ImageIteratorWithIndex, and that Value() is assignable only
for iterators over a non-const image.
@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 type:Style Style changes: no logic impact (indentation, comments, naming) labels Nov 5, 2026
@hjmjohnson

Copy link
Copy Markdown
Member

Awesome dzenanz! Thank you! We still have concerns that need to be addressed.

@dzenanz

dzenanz commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

It is a lot easier to review this way. I am still going through this.

@dzenanz

dzenanz commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

The last commit I somewhat carefully looked at is 632f19c.

@hjmjohnson

Copy link
Copy Markdown
Member

Thank you, @dzenanz. #7065 now uses this split, with the move-only commits rebased on #7119 and current main, and their subjects shortened to ITK's 78-character limit. Closing in favor of #7065.

@hjmjohnson hjmjohnson closed this Nov 5, 2026
@dzenanz
dzenanz deleted the pr7065-split branch November 5, 2026 21:34
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 type:Style Style changes: no logic impact (indentation, comments, naming) 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