Skip to content

Incorrect examples with reduce #1

@quicknir

Description

@quicknir

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions