C++ Logo

SG20

Advanced search

Subject: Re: A draft paper to fix the range-based for loop to make it teachable
From: Peter C++ (peter.cpp_at_[hidden])
Date: 2020-11-13 15:23:23


I am not against Nico's proposal at all. I just wanted to say there is more to do.

Regards
Peter

sent from a mobile device so please excuse strange words due to autocorrection.
Peter Sommerlad
peter.cpp_at_[hidden]
+41-79-432 23 32

> On 13 Nov 2020, at 22:20, Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]> wrote:
>
> Hi,
>
> Il 13/11/20 09:06, Peter C++ ha scritto:
>> FWIW, this is the approach other library functionality should consider to reduce the risk of dangling. either delete the temporary case, or think hard about a non-dangling return type, e.g., by value, if at all. may be we can find a solution to enable such a situation where it is obvious the programmer guarantees the lifetime of the temporary, but I am waiting for an insight, how to approach it.
>
> Isn't it a bit annoying however that the library is in itself inconsistent -- as_const/operator| on ranges/etc. are blocked for rvalue overloads, but min/max/get/etc. aren't?
>
> This proposal fixes a major use case, and yet we'll miss forever the ability of e.g. using
>
> for (auto && elem : getVector() | view::something)
>
> even if now it would actually be 100% safe. (And, unlike as_const, ranges don't look like can be fixed.)
>
> Thanks,
>
> --
> Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
> KDAB (France) S.A.S., a KDAB Group company
> Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
> KDAB - The Qt, C++ and OpenGL Experts
>


SG20 list run by sg20-owner@lists.isocpp.org

Older Archives on Google Groups