TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25287 10
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/

https://redd.it/1tn8jqi
@r_cpp
GitHub GitHub - atstana/undercurrent Contribute to atstana/undercurrent development by creating an account on GitHub.
More from @r_cpp
  1. Sep 29, 2026Boost.Graph 1.95 will be C++17 Dear Boost.Graph community, In two release cycles (Boost re…
  2. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  3. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  4. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  5. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  6. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →