Domanda

Qt offers a set of STL-like containers.

However, there is no container available, which stores ordered values by their order (like std::set) and QSet for some reasons behaves like std::unordered_set. I realize that probably O(1) lookups in the "set" data structure called might be a great thing, but I certainly cannot understand why this decision was made.

Which container should I use to store ordered item collections (I suspect that QMap with fictive values is a very poor choice) and why doesn't Qt offer something like std::set?

I guess there might be some technical reason behind this, but, unfortunately, I can't think of one.

È stato utile?

Soluzione

From Wikipedia:

Haavard Nord and Eirik Chambe-Eng (the original developers of Qt and the CEO and President, respectively, of Trolltech) began development of "Qt" in 1991

Also from Wikipedia, about the STL:

Andrew Koenig of Bell Labs had not become aware of the work and asked Stepanov to present the main ideas at a November 1993 meeting of the ANSI/ISO committee for C++ standardization. The committee's response was overwhelmingly favorable and led to a request from Koenig for a formal proposal in time for the March 1994 meeting. Despite the tremendous time pressure, Alex and Meng were able to produce a draft proposal that received preliminary approval at that meeting.

And from The Man himself:

"As I have often said, I consider not shipping a larger standard library my biggest mistake." --Bjarne Stroustrup

Qt developed independently. So it goes. Use QMap and move on with your life. :)

(Note: there is an unordered map in Qt, it's called QHash)

If you can't think of something useful or interesting to put in the value slot, then your program is probably not complicated enough to be making a fuss over. Are there data members in your key object that you could just as easily make the value in the map? Can you really not think of something to put there?

If you actually do wind up wasting a char per entry, then is that the real bottleneck in your system? Do you have metrics proving this? Etc, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top