[Development] User-defined literals for QString (and QByteArray)
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Fri Mar 5 14:00:27 CET 2021
Il 05/03/21 13:51, Andrei Golubev ha scritto:
> That said, QByteArray's ctor accepting char* is not explicit (which kind
> of makes sense) and we have this ambiguity for f(QByteArray) and
> f(QByteArrayView) I believe. But guessing that it's not expected that
> QByteArrayView would be as popular as QStringView.
Sure, but this results in functions overloaded for QByteArray and const
char *, not QByteArray and QByteArrayView -- see QByteArray's operators,
qCompress, etc.
> Thus, QByteArray str = "hello" works fine, so maybe no need to introduce
> a UDL for that class. OTOH, QString and QByteArray would have API
> differences (in some sense) yet again (and there's QByteArrayLiteral).
But the UDL you proposed is for the non-allocating path, so
QByteArray b = "hello"_qba;
is different from
QByteArray b = "hello";
Cheers,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20210305/271a6dba/attachment.bin>
More information about the Development
mailing list