[Development] HEADS-UP: QStringLiteral

Ville Voutilainen ville.voutilainen at gmail.com
Fri Aug 23 08:48:59 CEST 2019


On Fri, 23 Aug 2019 at 09:37, Mutz, Marc via Development
<development at qt-project.org> wrote:
> But up to and incl. C++17, the only way to make "foo"_qs work is by
> operator ""_qs(const char *, std::size_t), which is not a template, so
> all it can do is call QString::fromUtf8(), which would be a step back
> from what we have right now (since 5.7 or so, we guarantee that
> QStringLiteral doesn't allocate).
>
> @Ville: please correct me if I'm wrong in the above. And: what's the
> reason I can't use the template <char...> version for string-literal
> UDLs?

Looks correct to me. The reason why compile-time strings are not done
as separate
template arguments for each element of the string is to avoid your couple-dozen
strings taking megabytes of memory doing compilation.

For what it's worth, adding all kinds of literals and intermediate
proxy types is something that's plausible
to do now, but the standard is moving away from such direction, and
the committee seriously plans to
make code like

constexpr std::string = "foo";

Just Work. So rather than have funky literals and other auxiliary
types, the direction is to make string
work for more cases. I'm not sure whether that changes anything with
our from-utf8 an from-latin1
QString initialization scenarios.



More information about the Development mailing list