C++ Logo

sg20

Advanced search

Re: [SG20] A draft paper to fix the range-based for loop to make it teachable

From: Yehezkel Bernat <yehezkelshb_at_[hidden]>
Date: Tue, 10 Nov 2020 16:53:12 +0200
On Tue, Nov 10, 2020 at 4:38 PM Amir Kirsh via SG20 <sg20_at_[hidden]>
wrote:

> For example: don't return a const reference to a parameter that you got
> as const ref. It might be a temporary (great example I send my students to is
> here <http://www.youtube.com/watch?v=lkgszkPnV8g&t=13m0s>).
>
>
I don't think the standard library agrees. E.g.
https://en.cppreference.com/w/cpp/algorithm/min
This is probably the responsibility of the caller to not hold things as
references in such cases.



> But fixing just the range-based-for may lead to even more confusion.
>

I like this argument!



>

Received on 2020-11-10 08:53:33