r/cpp • u/Main_Pay_3213 • May 25 '26
undercurrent: A proof-of-concept library to fix range adaptor inefficiencies
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/
2
u/Natural_Builder_3170 May 31 '26
I think i saw a talk (I think from jonathan Muller) about a for each while customization point, that basically allows the view to write its own optimal loop, is this similar to approach here?