[Interest] QMap::keys() / Qt6

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue Jan 2 23:24:19 CET 2018


Il 02/01/2018 18:37, Jason H ha scritto:
>> Is it possible to add a helper function for this somewhere (or is it
>> already available) or another easier way?
> 
> I complained about a lack of a generic iterator class back in the spring of last year[1]. Thiago seems to have one waiting for Qt6, because as a developer, I don't want to to care what kind of iterable you pass to me, I just want to iterate on it.

But this doesn't really require a "generic iterator class", does it? The 
function looked for here is really some variation around this:

> template <typename K, typename V>
> auto mapKeysToVector(const QMap<K, V> &map)
> {
>     QVector<K> result;
>     result.reserve(map.size());
>     std::copy(map.keyBegin(), map.keyEnd(), std::back_inserter(result));
>     return result;
> }

The question is more broad and about how to avoid similar functions 
popping up everywhere in Qt codebase. I don't have a good answer for 
that except for "please start collecting them somewhere in the QtPrivate 
namespace".

My 2 c,

-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180102/f93cfc2c/attachment.bin>


More information about the Interest mailing list