Simple enough:
for (int i = 0; auto const &e : some_container)
DoSomeProcessing(e, i++);
-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mi 01.03.2023 09:50
Betreff: [std-proposals] Array Index in Range-based For Loops
An: std-proposals <std-proposals@lists.isocpp.org>;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
Sometimes I write code like this:
size_t i = -1;
for ( auto const &e : some_container )
{
++i;
DoSomeProcessing(e, i);
}
It would be nice if range-based for loops had an implicit counter
variable, so that the above code snippet could simply be written as:
for ( auto const &e : some_container )
{
DoSomeProcessing(e, __i);
}
I propose that this would work even with containers that don't allow
random access.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals