[Development] QList

Thiago Macieira thiago.macieira at intel.com
Tue Mar 28 07:01:51 CEST 2017


On segunda-feira, 27 de março de 2017 14:53:05 PDT Giuseppe D'Angelo wrote:
> Why should it bad if what you want return is precisely a "const
> reference" over QString-like data? Isn't that the whole reason why we
> have functions returning QStringRef right now (lacking a QStringView)?
> (And also the reason why QStringView itself returns QStringViews?)

The functions returning QStringRef are not a good practice. They are bad API 
in the first place, so please don't make the situation worse.

Now, replacing QStringRef with QStringView may be acceptable, as it makes the 
problem not much worse. But at least in the case of QXmlStreamReader, it does, 
so that won't work.

> Example of use case: a tokenizer operating over QString-like data,
> returning each token as a QStringView, with no memory allocations --
> possibly even noexcept (narrow contract on the source string). Why would
> I want to return QStrings for this use case and super-pessimize it?

Tht's probably acceptable. We need to study each case in a case-by-case basis.

Rule of thumb is to return QString.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list