[Development] Views in APIs (was: Re: QString and related changes for Qt 6)

Ville Voutilainen ville.voutilainen at gmail.com
Wed May 13 11:46:53 CEST 2020

On Wed, 13 May 2020 at 12:37, Marco Bubke <Marco.Bubke at qt.io> wrote:
> auto view3 = myObject.getCopy()[42].getView(); // not safe, copy is destroyed
> AFAIK you can say that a rvalue should not return a reference by using ref-qualified member functions.
> View getView() const & { return v;}


whatever_function(myObject.getCopy()[42].getView()); // never dangles,
so always safe

Disabling reference returns for rvalues prevents such forwarding cases
from working, and you need
to declare a separate lvalue to make your code work.

More information about the Development mailing list