[Qt5-feedback] C++0x: QString literals

João Abecasis joao.abecasis at nokia.com
Wed Jul 13 15:35:32 CEST 2011


Stefan Majewsky wrote:
> C++0x seems to be adding support for user-defined literals. [1] Is
> Nokia planning to add support for this to replace e.g. QLatin1String?
> 
> Code could then look like this:
> 
>> void f(const QString&);
>> //...
>> f(QLatin1String("foobar")); //C++ pre-0x
>> f("foobar"q); //C++0x

[...]

> [1] http://en.wikipedia.org/wiki/C++0x#User-defined_literals

Since there's no compiler currently supporting user-defined literals we don't have plans to use that feature at the moment, although I've seen the idea entertained internally.

That said, we are adding support for having QString and QByteArray use static read-only data. This reduces the need for run-time initialization and memory allocation giving you essentially "free" read-only QString.

Look at these commits in qtbase for more information:

    commit ee85e9cc10bc6874c892b09fa54b5dbd79854069
    Author: Lars Knoll <lars.knoll at nokia.com>
    Date:   Wed Jul 6 09:21:10 2011 +0200

        Support for compile time generated QStrings

and also,

    commit ad35a41739c8e1fb6db62ed37b764448b2e59ece
    Author: Lars Knoll <lars.knoll at nokia.com>
    Date:   Mon Jul 11 23:16:58 2011 +0200

        Refactor QByteArray to allow for const data

Cheers,


João



More information about the Qt5-feedback mailing list