fix: std::ranges fixes done by AI#5311
Open
asalzburger wants to merge 9 commits intoacts-project:mainfrom
Open
fix: std::ranges fixes done by AI#5311asalzburger wants to merge 9 commits intoacts-project:mainfrom
asalzburger wants to merge 9 commits intoacts-project:mainfrom
Conversation
Contributor
andiwand
reviewed
Apr 3, 2026
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
Co-authored-by: Andreas Stefl <stefl.andreas@gmail.com>
|
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.



C++20
std::rangescleanups (Sonar)These have been done within cursor using the output of our SonarCloud run
Summary
This PR applies Sonar-driven updates to prefer
std::ranges::algorithms that take a range (and related range style) across Core, while keeping behaviour identical to the pre-change code. It also fixes a regression ingetMinMaxAndBinCountintroduced when first switching tostd::ranges::unique, which had broken magnetic-field and material-map unit tests until the unique-count logic was corrected.20 files, ~130 insertions / 129 deletions (no functional intent beyond the fixes below).
Motivation
Address a batch of Sonar issues whose messages ask to use
std::ranges::find/transform/copy/upper_bound/lower_bound/min_element/max_element/count_if/remove_if/unique/all_of/any_of, or to prefer range-based loops /std::ranges::for_eachwhere applicable.(One reported item for
std::ranges::set_differenceinLayerCreator.cppwas not applied: that call site is not present in the current tree / line mapping was stale.)What changed
Algorithms and loops
SubspaceHelpers:std::find/std::transform→std::ranges::findon subranges,std::ranges::transform; duplicate detection incheckSubspaceIndicesuses a tail subrange.TrackStateProxyCommon:std::ranges::transformfor projector subspace copy.GeometryHierarchyMap,SurfaceArrayCreator,Axis,TrackSelector,BinningData:upper_bound/lower_bound→std::ranges::*+std::ranges::distancewhere needed.BinUtility::inside: loop →std::ranges::all_ofover binning data.ConstrainedStep:std::ranges::min_elementon step values.MultiStepperLoop:std::ranges::count_if; removal usesstd::ranges::remove_if+eraseon the returned tail (see below).GsfUtils: range-basedforfor weight normalization;std::ranges::min_elementfor chi² minimum;std::all_of(begin, end, …)kept for finite-weight check because the const component iterable does not modelstd::ranges::input_rangewith libc++.Grid:std::ranges::copy.BoundingBox.ipp:std::ranges::transform(+<algorithm>).Table: range-for over columns;std::ranges::transformfor lowercasing alignment strings.Helpers: see critical fix below.CuboidVolumeBounds:std::ranges::any_of.CuboidVolumeStack/CylinderVolumeStack/CylinderVolumeBuilder:ranges::copy/transform/min_element/max_element.GreedyAmbiguityResolution:std::ranges::max_elementon selected tracks.libc++ / API constraints
MultiStepperLoop:std::erase_ifis not available forboost::container::small_vectoron this standard library. Replaced withstd::ranges::remove_ifanderaseon the subrange of elements to drop (same effect as erase–remove).GsfUtilschecks:std::ranges::all_ofon the const component iterable fails constraints; keptstd::all_ofwith explicit iterators.Bugfix:
detail::getMinMaxAndBinCount(Helpers.hpp)std::ranges::uniquereturns the subrange[ret, end)(duplicate tail), not the unique prefix. The unique-element count must be:std::ranges::distance(xPos.begin(), uniqueTail.begin())Using
distance(uniqueTail)counted duplicates, brokexBinCount,stepX, and surfaced as NaN / inf andstd::out_of_rangein TextMagneticFieldIo, BFieldMapUtils, MaterialMapUtils, and RootMagneticFieldIo. This PR corrects that and documents it in the file comment.Files touched
Testing
acts build acts-sonarcloudsucceeds.TextMagneticFieldIo,BFieldMapUtils,MaterialMapUtils,RootMagneticFieldIoacts test acts-sonarcloud).Not in this PR
Maintainer checklist
getMinMaxAndBinCountfix (restores correct bin count vs broken intermediateranges::uniqueusage)--- END COMMIT MESSAGE ---
Any further description goes here, @-mentions are ok here!
feat,fix,refactor,docs,choreandbuildtypes.