Make the batcher and partition iterators usable - #103
Open
susilehtola wants to merge 1 commit into
Open
Conversation
SphericalMicroBatcher::const_iterator declared its comparison operators
taking the non-const `iterator` type:
bool operator==( iterator other ){ ... }
There is no conversion between the two, so comparing two const_iterators
was a hard error and the loop the class exists to support could not be
written over a const batcher. A const batcher also had no begin()/end()
at all, only cbegin()/cend(), so range-for over one failed by a second
independent route.
RadialGridPartition::rgp_iterator had the same class of bug in its
post-increment, which declares `iterator retval = *this;` -- the enclosing
class's non-const typedef, so const_iterator::operator++(int) could never
instantiate.
Fix both, and give the batcher const begin()/end().
While here, three related defects in the same iterators:
* operator+ mutated *this and returned a reference to it. That is
operator+= under the wrong name; at() worked only because it discards
the iterator afterwards. Return a copy and take a difference_type.
* difference_type was spelled `different_type` and iterator_category was
spelled `iterator_catagory`, so std::iterator_traits saw neither and no
standard algorithm could use these iterators.
* With the traits now visible, `reference = value_type&` would have been
a trap: operator* returns a prvalue, so binding a reference to it
dangles. Use the proxy-iterator spelling instead (reference =
value_type, pointer = void).
range() and operator* are now const, as they never mutated anything.
The existing test called cbatcher.at(i) but never iterated a const
batcher; add both a range-for and an explicit cbegin()/cend() loop.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FDTFYJMQ76iujDFNHzZyXF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SphericalMicroBatcher::const_iterator declared its comparison operators
taking the non-const
iteratortype:There is no conversion between the two, so comparing two const_iterators
was a hard error and the loop the class exists to support could not be
written over a const batcher. A const batcher also had no begin()/end()
at all, only cbegin()/cend(), so range-for over one failed by a second
independent route.
RadialGridPartition::rgp_iterator had the same class of bug in its
post-increment, which declares
iterator retval = *this;-- the enclosingclass's non-const typedef, so const_iterator::operator++(int) could never
instantiate.
Fix both, and give the batcher const begin()/end().
While here, three related defects in the same iterators:
operator+= under the wrong name; at() worked only because it discards
the iterator afterwards. Return a copy and take a difference_type.
different_typeand iterator_category wasspelled
iterator_catagory, so std::iterator_traits saw neither and nostandard algorithm could use these iterators.
reference = value_type&would have beena trap: operator* returns a prvalue, so binding a reference to it
dangles. Use the proxy-iterator spelling instead (reference =
value_type, pointer = void).
range() and operator* are now const, as they never mutated anything.
The existing test called cbatcher.at(i) but never iterated a const
batcher; add both a range-for and an explicit cbegin()/cend() loop.
Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FDTFYJMQ76iujDFNHzZyXF