ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 440 forks source link

Fold algos #1628

Closed brevzin closed 3 years ago

brevzin commented 3 years ago

This is my current intended direction for what to propose in P2322 (the latest draft still uses fold_left and fold_right, but the next one will propose what I'm doing in this PR). There's a few more fold algorithms I intend to add to range-v3 but not std (like a short-circuiting fold and a fold that returns the iterator that it leaves off at), but the combinatorial explosion is a bit much, so I thought I'd start with this.

I like going with Haskell's names here because they're short, symmetric, and unambiguous. Some languages went the route of using fold (for the algorithm that takes an initial value) and reduce (for the algorithm that doesn't), Rust being the latest addition to that unfortunate club, and we can't do that even if we wanted to.