rubenvb
rubenvb

Reputation: 76681

Why do Qt containers like QList and QVector not have iterator range constructors?

The Standard library containers in C++ have constructors that take iterator ranges. This is handy when the content of an input container is convertible to, but not the same as the content in the resulting container, or even if the container is just different. The constructor overload allows for this type of conversion to happen in a surrounding class's constructor, which leads to less clutter in the code.

So the question arises, why don't the Qt containers have this overload? Is it an oversight or is there a reason behind this clunky design choice?

Upvotes: 3

Views: 1812

Answers (2)

peppe
peppe

Reputation: 22796

There is no reason except for "nobody implemented them so far", as the Qt Project doesn't have an infinite development bandwidth.

Speaking of such missing features, you could say the same for:

  • the fact that you can't store move-only types in Qt containers due to implicit sharing;
  • the lack emplacement functions (and their upcoming try versions for associative containers);
  • the lack of rvalue-overloaded functions (no QList::push_back(T &&));
  • QList having no equivalent in the STL and being a very strange monster with serious performance issues. It is now acknowledged that it should have never been made the "good generic container" used everywhere in Qt;
  • no exception safety guarantees whatsoever;

and so on.

There's lots of discussion going on these days (f.i. see this thread) about the poor state of Qt containers when compared to the STL ones, to the point that we're starting using STL containers in Qt's own implementation.

Unless you have specific reasons for using the Qt ones (say, you need to pass them to Qt-ish APIs, or you like/need implicit sharing, etc.), these days STL containers are way better than Qt ones.


Update: QList in Qt 6 is going to be a proper vector, and QVector (In Qt 6) will be an alias to QList. Some of the remarks above will not apply any more. I'm not modifying the rest of the answer as that still applies to Qt 5.15.

Upvotes: 7

demonplus
demonplus

Reputation: 5801

There are several features of STL containers lacking in Qt containers. You can find a great review of them in blog of Marc Mutz here.

To my opinion, the plan was to replace the feature of taking with iterator ranges in construction with qCopy, http://doc.qt.io/qt-4.8/qtalgorithms.html. In Qt 5 many iterator and const_iterator features for containters appeared in Qt and probably appropriate constructors for QList and QVector may also appear in later versions (not announced, just a thought).

Upvotes: 0

Related Questions