Skip to content

fix min/max variadic fold#1

Open
frewsxcv wants to merge 1 commit into
carbonengine:mainfrom
frewsxcv:fix/min-max-variadic-fold
Open

fix min/max variadic fold#1
frewsxcv wants to merge 1 commit into
carbonengine:mainfrom
frewsxcv:fix/min-max-variadic-fold

Conversation

@frewsxcv

Copy link
Copy Markdown

The fold expression (r = std::min(arg0, args)), ... compared arg0 against each successive args element instead of folding through r, so for three or more arguments the result was min(arg0, last_arg) rather than the true minimum. e.g. min(5, 3, 7) returned 5.

The single-argument overload (empty parameter pack) returned r without ever assigning it — undefined behavior.

Initialize r = arg0 and fold through r. Same fix for maxv.

The fold expression `(r = std::min(arg0, args)), ...` compared `arg0`
against each successive `args` element instead of folding through `r`,
so for three or more arguments the result was `min(arg0, last_arg)`
rather than the true minimum. e.g. `min(5, 3, 7)` returned 5.

The single-argument overload (empty parameter pack) returned `r`
without ever assigning it — undefined behavior.

Initialize `r = arg0` and fold through `r`. Same fix for `maxv`.
@filipppavlov

Copy link
Copy Markdown
Contributor

Hi @frewsxcv

Thank you for the PR, and apologies for the late response. We are still in the process of sorting out some details around contribution guidelines and PR templates.

The fix itself looks good; we'll merge it as soon as we figure out the problems on our end.

I will get back to you once we are in a position to accept contributions.

@ccpgames-carbon

ccpgames-carbon commented Jul 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants