Purpose of STL-style parts of collection classes
-
Most people (myself included) tend to praise Qt because its API is much more pleasant than STL. But Qt does provide STL-style members and iterators in its collection classes.
The main reason I see for this is to make them work with generic algorithms (from STL, or custom ones). But this doesn't work as it should. Qt has some quite important incompabilities.
Two of them I have encountered just wanting to write a proper lambda-enabled for_each for associative containers are:
- STL's cbegin is called constBegin (and the same for cend)
- QMap/QHash iterators have nothing in common to STL's iterators
-
STL's iterator is a 'pointer' to a pair, Qt's is a 'pointer' to a value
-
Qt's pointer has key and value methods, while in STL you use first and second members of the pair
// Qt:
it.key(), it.value()
// STL:
it->first, it->second
-
This means that more advanced custom generic algorithms will fail either on Qt or STL. Or, you need to do a lot of template magic just to differentiate those two and provide the same API for both.
Any thoughts on this? Is this something that should be fixed, forgotten, ... or does STL-style API in Qt serves some strange purpose I just don't see.
-
I was wondering about that, too.
-
I've posted a bug report which I guess will go without comments :/
https://bugreports.qt-project.org/browse/QTBUG-25997I'd even work on this if somebody said 'hmh, that should be fixed'.
The issue is that it could break api for the case of operator->, the rest i think could be tricked into proper behavior.