Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect examples with reduce #1

Open
quicknir opened this issue Feb 2, 2022 · 0 comments
Open

Incorrect examples with reduce #1

quicknir opened this issue Feb 2, 2022 · 0 comments

Comments

@quicknir
Copy link

quicknir commented Feb 2, 2022

The examples of count and any_of implemented using reduce aren't correct: https://github.com/codereport/Algorithms/blob/master/stl_14_reduce_accumulate.cpp. Because reduce can be applied out of order, you have to have associative, commutative functions. The functions being passed here don't even expect the same type for their left and right argument, so they're clearly not commutative. They could be changed to use accumulate, although in the case of any_of you're still better off using find_if.

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

No branches or pull requests

1 participant