2 ms·
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 t
by pjmlp 4mo 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 https://cpp.godbolt.org/z/3r8rPdjbG
- Bimos 4mo agoI'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?
- spider-mario 4mo agoYes. You don’t sound that confused?
- pjmlp 4mo agoCopy paste error, too late to update the comment, it should be a plain i.