[Development] Rvalue pinning in Qt
Thiago Macieira
thiago.macieira at intel.com
Mon Jun 20 17:39:55 CEST 2022
On Monday, 20 June 2022 07:46:57 PDT Giuseppe D'Angelo via Development wrote:
> A fancy name for: "if a function/class is operating on a rvalue, should
> it store a copy of it in order to keep it alive?". Consider
In other words, remove the rvalue reference and store a copy from the const-
lvalue reference overload you already have.
> > std::u16string someLongString = u"...";
> > auto tokenizer = QStringTokenizer(someLongString, u"X");
>
> For this reason QStringTokenizer moves and stores the input if it's an
> rvalue, but only keeps a reference if it's an lvalue.
This means QStringTokenizer must have a QString member and a QString & member.
The simplest implementation removes one of them.
> > QString s = getString();
> > auto tok = QStringTokenizer(s, u"x");
>
> would take a copy (given `s` is a view after [4]), while now it only
> takes a reference.
Yup.
> Opinions?
My only objection is to calling this by a fancy name, "rvalue pinning". Simply
call what it is: take all parameters by const-lvalue and never store a
reference.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Cloud Software Architect - Intel DCAI Cloud Engineering
More information about the Development
mailing list