Hacker News new | ask | show | jobs
by pjmlp 18 days ago
Even more modern, we are getting C++26 nowadays.

CTADs for vector (no need for explicit string), ranges enumeration, and range-based for-loop with structured types

    int main() {
        vector vec = { 
            "the", "quick", "brown", "fox", 
            "jumped", "over", "the", "lazy", "dog" 
        };

        for (auto&& [i, it] : vec | std::views::enumerate)
            println ("{}:{}", ++i, it);
    }
Compiler explorer example, https://cpp.godbolt.org/z/3r8rPdjbG
1 comments

I'm super confused. In your example, ++i is equivalent to (i+1) and the loop updates i itself. But with the syntax in the blogpost, i is only initialized, and it is the ++i that updates the value?
Copy paste error, too late to update the comment, it should be a plain i.
Yes. You don’t sound that confused?