I need to add two types int
and auto
to the loop. But maybe I want to add a couple more types. Maybe I can use lambda.
I need the best way to implement this.
for(int i, auto h; i < 10; i++)
{ }
I need to add two types int
and auto
to the loop. But maybe I want to add a couple more types. Maybe I can use lambda.
I need the best way to implement this.
for(int i, auto h; i < 10; i++)
{ }
No, you can't declare multiple types in the for loop initialiser.
Bearing in mind that you can initialise them, a reasonable alternative is
{
Foo h;
for (int i = 0, h = Foo(); i < 10; ++i){
}
}
where the outer braces stop h
from leaking into the surrounding scope. Another idea would be to use a std::tuple
or similar.