C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Range-based for loop

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 16 Nov 2023 14:03:24 +0100
Il 16/11/23 13:31, Ghevond Gevorgyan via Std-Proposals ha scritto:
>
> Why is the range variable not forwarded? Is there a specific reason for
> this?
>

If you forward the range as an rvalue to the call to begin(), then you
cannot call end() on it afterwards. That's a "use-after-move", and
there's no guarantee on what end() will end up doing.

Maybe it will just work, maybe it will crash / trigger UB / return an
iterator not reachable from begin() / and so on. (Note: I'm a strong
proponent of "use after move is UB".)

Do you have a use case for having only rvalue begin()/end()?

Thanks,
-- 
Giuseppe D'Angelo

Received on 2023-11-16 13:03:28