Il 21/06/20 20:07, Elvis Stansvik ha scritto:
I'm all for Qt offering faster way to do things. I expect that. But I
also wonder: Why remove the slower alternative for those who value
readability over optimality in the cases where the extra performance
is not needed? In the docs, the slow alternative could have pointers
to the fast alternative, and the user could make an informed choice.

Let me elaborate on what I commented on the bug report:

1) no API should lead to naturally writing bad code;

2) no API should encourage premature pessimization;

3) APIs should encourage the natural discovery of the best tool for a given job. If your job is to remove duplicates, the API should favour an algorithm for that, not the toSet().toList() combo, which is just an antipattern!

4) as developers of Qt: we must care about all of the above; and bad habits on user side shouldn't result in bad APIs, in the name of convenience or whatever;

5) ultimately, the most direct replacement of toContainer() is

container | ranges::to<AnotherContainer>

which isn't that much of an extra burden to learn / to type rather than toContainer(), and it's also obviously more general.

---

In other words: if you "don't care", you can just replace list.toSet() with list | ranges::to<QSet>. You can do it today, using just a C++14 compiler (and you need a C++17 compiler anyhow if you're aiming for Qt 6).

Back on to OP's issue, with this code using deprecated APIs:

    QSet<QString> 
missingKeys{customLines.keys().toSet().subtract(customLinesColor.keys().toSet())};

Then the "don't care" port can be done by something like:

QSet<QString> missingKeys = customLines.keys() | ranges::to<QSet>;
missingKeys.subtract(customLinesColor.keys() | ranges::to<QSet>);


If nobody ever told you about toSet(), and only told you about ranges::to<X>, would you be upset by toSet()'s deprecation?


My 2 c,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to