[Development] How to make a fancy QMap c++17 initializer_list

Henry Skoglund fromqt at tungware.se
Mon Jul 24 09:23:38 CEST 2017


Hi,

I think there are almost no need for deduction guides, for example a 
similar program using QVector compiles fine on gcc-7:

--------------------------------------------------------------
#include "qapplication.h"
#include "qvector.h"
#include "qdebug.h"

int main(int argc, char *argv[])
{
     QApplication a(argc, argv);

     QVector vec = {"Now", "is", "the", "time", "for", "all"};

     for (auto v : vec)
         qDebug() << v;
}
--------------------------------------------------------------

It's just QMap that I got stuck on, but as you say, it's very bleeding 
edge, mostly for showing off :-)

/Henry

On 2017-07-24 09:00, 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.
> 
> Patches welcome, bug reports accepted.
> 
> Thanks,
> Marc
> 
> On 2017-07-24 06:32, Henry Skoglund wrote:
>> Hello, I've been testing more C++17 class template auto deduction
>> awith gcc-7, and got stuck on QMap, consider this simple test program:
>>
>> -------------------------------------------------------------
>> #include "qapplication.h"
>> #include "qmap.h"
>> #include "qdebug.h"
>>
>> int main(int argc, char *argv[])
>> {
>>     QApplication a(argc, argv);
>>
>>     QMap m = {std::pair{2,"score"}, {4,"seven"}, {1,"Four"},
>> {5,"years"}, {3,"and"}, {6,"ago"}};
>>
>>     for (auto v : m)
>>         qDebug() << v;
>> }
>> -------------------------------------------------------------
>>
>> I really would like to just write a {{Key,T}..} list but it will not
>> compile. As a kludge/compromise it works if I write "std::pair" around
>> the first {} pair, to force the compiler to see it my way. Then the
>> speech of Mr. Lincoln comes out fine.
>>
>> In C++17 you should be able to fix this through a "User-defined
>> deduction guide" to help the compiler. I've been trying various
>> template one-liners but alas, I think my brain is too small. Anyone
>> got a clue?
>>
>> Rgrds Henry
>>
>> _______________________________________________
>> Development mailing list
>> Development at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/development
> 





More information about the Development mailing list