Hi, I'm a hobbyist programmer and I recently came across Barry Revzin's blog post about inefficiencies in the C++ ranges library when filter or reverse is mixed into an adaptor chain. I wanted to see if I could do something about it, and after some experimentation I ended up with this library: undercurrent.
The core idea is a customization point object
uc::advance_while, which descends the iterator hierarchy recursively rather than operating at the top level. This allows algorithms to do their work at the lowest iterator level, avoiding redundant predicate evaluations.I observed a significant speed improvement with an adapter chain like
take_while | transform | filter | reverse. On Clang 22 + libc++, I'm seeing roughly 16x speedup over std::ranges. Though MSVC shows a smaller improvement (\~2x). Currently supports a minimal set of adaptors and algorithms. GCC is not yet working, likely due to module-related issues.I'd love to hear your feedback, thoughts, or any edge cases I should consider!
GitHub: https://github.com/atstana/undercurrent
Barry Revzin's blog: https://brevzin.github.io/c++/2025/04/03/token-sequence-for/
https://redd.it/1tn8jqi
@r_cpp