Nope, that would not be C++ if it wasn’t broken:

class C1
{
public:
    std::string_view getMember() const & { return member; }
    std::string member;
};

std::string_view m = C1().getMember(); // compiles!

You have to delete the method explicitly:

std::string_view getMember() const && = delete;

Now compilation fails:

call to deleted member function 'getMember'
    std::string_view m = C1().getMember();
                         ~~~~~^~~~~~~~~

> 13 мая 2020 г., в 11:31, Marco Bubke <marco.bu...@qt.io> написал(а):
> 
>  
> 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;}

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to