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

Marc Mutz marc.mutz at kdab.com
Mon Jul 24 09:00:36 CEST 2017


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