I have just discovered that it is possible to place a declaration also in the second "parameter" of a for-statement. But I was not able to find anywhere how it behaves with regard to the construction/destruction of the object declared in that parameter.
Let's have this simple code:
struct C {
C() { puts("constr"); }
~C() { puts("destr"); }
};
int main() {
for (int i = 0; auto h = std::make_unique<C>(); i++) {
puts("in");
}
}
Please could you tell me when h is destroyed? (after puts("in"), i++, ...?). How does it behave with break; and continue;?
Thanks for clarification!