Date: Tue, 28 Jan 2025 19:43:20 +0100
Hi!
I'm trying out c++23 std::generator and noticing that I cannot safely pass arguments to my generators that are temporaries such as std::initializer_list. It seems like this is because promise_type's initial_suspend returns suspend_always, so passed temporaries are out of scope as soon as initial code is executed.
Where can I read about this and best practices, or is it a mistake? It looks like a mistake to me.
My understanding is that if initial_suspend returned suspend_never, then the developer could accept temporaries and copy their contents to the stack in the initial code block of the generator. But as it is, there can be surprising subtle memory access errors in code not aware of the limitation that generators cannot safely accept temporaries at all.
Ideally there would be some way to configure this.
Karl Semich
I'm trying out c++23 std::generator and noticing that I cannot safely pass arguments to my generators that are temporaries such as std::initializer_list. It seems like this is because promise_type's initial_suspend returns suspend_always, so passed temporaries are out of scope as soon as initial code is executed.
Where can I read about this and best practices, or is it a mistake? It looks like a mistake to me.
My understanding is that if initial_suspend returned suspend_never, then the developer could accept temporaries and copy their contents to the stack in the initial code block of the generator. But as it is, there can be surprising subtle memory access errors in code not aware of the limitation that generators cannot safely accept temporaries at all.
Ideally there would be some way to configure this.
Karl Semich
Received on 2025-01-28 18:43:21