[Development] How to make a fancy QMap c++17 initializer_list
Henry Skoglund
fromqt at tungware.se
Mon Jul 24 18:45:40 CEST 2017
On 2017-07-24 16:53, Thiago Macieira wrote:
> On Monday, 24 July 2017 00:00:36 PDT Marc Mutz wrote:
>> Hi,
>>
>> We haven't added deduction guides to any Qt class, yet. If you want to
>> use bleeding-edge C++, use C++, iow: std::map.
>
> std::map currently (GCC 7.1.1) works less well than QMap, since you can't even
> trick it. The std::pair that std::map uses requires a const Key, which you
> can't get with a primitive prvalue.
>
Tested a bit more, here's the current best effort for both maps
(yielding 12 words from Pres. Lincoln) and indeed Qt is ahead in this
game (std::map requires more handholding):
---------------------------------------------------------------------------------
#include "qapplication.h"
#include "qmap.h"
#include "map"
#include "qdebug.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMap m1 = {std::pair{2,"score"}, {4,"seven"}, {1,"Four"},
{5,"years"}, {3,"and"}, {6,"ago"}};
std::map m2 = {std::pair<const int,QString>{8,"fathers"},
{10,"forth"}, {7,"our"}, {11,"on"}, {9,"brought"}, {12,"this"}};
for (auto v : m1)
qDebug() << v;
for (auto v : m2)
qDebug() << v.second;
}
---------------------------------------------------------------------------------
More information about the Development
mailing list