C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Array Index in Range-based For Loops

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 2 Mar 2023 09:12:08 +0000
On Thu, Mar 2, 2023 at 12:19 AM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> > >I'm not gonna include a header file and use that horrible syntax.
> > >Having an implicit variable called "__i" would be much better.
> >
> > What would it be called in an inner loop? __j?


How about the outermost is __i, and then the next inner one is __j,
then __k, until we get to __z. That would accommodate 18 nested loops.

for ( auto &container : container_of_containers )
{
    cout << __i << endl;

    for ( string &e : container )
    {
        cout << __i * __j << end;

        for ( char const c : e )
        {
            cout << __k << " originating from " << __i << endl;
        }
    }
}

Received on 2023-03-02 09:12:20