C++ Logo

std-proposals

Advanced search

Re: [std-proposals] for ( repeat_count )

From: Matthew Taylor <mjtaylor214_at_[hidden]>
Date: Mon, 23 Oct 2023 21:58:50 +0000
>I had proposed before that all 'for' loops should have an implicit variable '__i' keeping count of the iterations, something like:
>for ( auto &e : my_vector ) SomeFunc( e, __i );
>Of course it gets more complicated if you have nested loops [...]

I'm not sure I follow why adding an implicit variable which does something that for loops have already been able to do since time immemorial is a good idea. Nor do I see why that's preferable to either restructuring your loop, or (in the very rare situation you want both a range-based for loop with an index) rolling your own solution manually.

I think the solution here is to write your own code which semantically does what you want it to do, rather than ask for this very specific use-case be added to the standard.


Received on 2023-10-23 21:58:54