Get the latest tech news
Using Token Sequences to Iterate Ranges
There was a StackOverflow question recently that led me to want to write a new post about Ranges. Specifically, I wanted to write about some situations in which Ranges do more work than it seems like they should have to. And then what we can do to avoid doing that extra work. I’ll offer solutions — one sane one, which you can already use today, and one pretty crazy one, which is using a language feature we’re still working on designing, which may not even exist in C++29.
I’ll offer solutions — one sane one, which you can already use today, and one pretty crazy one, which is using a language feature we’re still working on designing, which may not even exist in C++29. It turns out that reversing a range is one of those sneakily complicated algorithms, that a lot of people will get wrong the first couple times they try to write it. Conceptually, the recursion is not that complicated — nor is it altogether different from what you would write in direct template code attempting to implement in a sane way.
Or read this on Hacker News