Unit: iterate SResourcePack by index instead of std::views::enumerate - #3029
Closed
tomjn wants to merge 1 commit into
Closed
Unit: iterate SResourcePack by index instead of std::views::enumerate#3029tomjn wants to merge 1 commit into
tomjn wants to merge 1 commit into
Conversation
SplitResourcePackIntoPositiveNegative used std::views::enumerate, the only std::ranges/std::views use in this file. The C++23 enumerate view (P2164) is not available on all standard libraries we target (notably libc++ on Apple Clang). Use a plain index loop over SResourcePack::res[0..MAX_RESOURCES] instead. This matches how the rest of the codebase already iterates SResourcePack (see rts/Sim/Misc/Resource.h, which uses for (int i = 0; i < MAX_RESOURCES; ++i) throughout), and removes a portability blocker without changing behavior. Surfaced by the macOS port (beyond-all-reason#2991), which carried this as an __APPLE__-gated fallback; applying it unconditionally means no platform gate is needed. Co-authored-by: iamaperson000 <kanishkv99@gmail.com>
Collaborator
|
I specifically used enumerate because ongoing resource work will decouple the underlying array from how many resources there actually are. Use d3dd051 instead. |
Contributor
Author
|
Closing — @sprunk confirmed |
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.
What
SplitResourcePackIntoPositiveNegativeinUnit.cppiterated aSResourcePackwithstd::views::enumerate:This is the only
std::ranges/std::viewsuse in the file. It's replaced with a plain index loop:Why
std::views::enumerate(C++23, P2164) is not available across all standard libraries we target — notably libc++ on Apple Clang. The index loop is portable, behavior-identical, and matches how the rest of the codebase already iteratesSResourcePack—rts/Sim/Misc/Resource.husesfor (int i = 0; i < MAX_RESOURCES; ++i)throughout. Theenumeratecall here was the odd one out.MAX_RESOURCESis 2, so there is no readability cost.Why this is cross-platform
No behavior change on any platform;
masterbuilds fine today, this just removes a libc++ portability blocker so no platform-specific fallback is needed downstream.Provenance
Surfaced by the macOS port (#2991), which carried this same index loop as an
__APPLE__-gated fallback (author: iamaperson000, credited viaCo-authored-by). Applying it unconditionally means the macOS branch needs no gate here at all.