C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 17 Nov 2023 11:43:59 -0500
On Fri, Nov 17, 2023 at 3:50 AM Ghevond Gevorgyan via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi Giuseppe,
>
> Thank you for your explanation.
>
> I cannot provide a specific use case for it,

Well, if you can't say when it would genuinely be useful, why should
the standard be changed?

> but my point is that there is a definition like this:
>
> init-statementopt auto &&range = for-range-initializer;
>
> and then there are `range.begin()` / `range.end()` calls which ignore the value category of the expression. This seemed weird to me. I think if there were a single function to get `begin()` and `end()` like this: std::pair<Iter, Iter> begin_end() &&; it would be okay.
>
> Also worth noting is that the use-after-move has some well-defined behaviors in the standard, for example

But most don't. In particular, many ranges won't do anything
meaningful if you call `begin`, move from them, and then call `end` on
the moved-from object.

Received on 2023-11-17 16:44:19