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`.
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.

1 participant