Criteria for selecting the right STL container for the job?
-
22-07-2019 - |
Question
Do you just base your STL container selections on the following attributes?
- Searching/Updating
- Insertion and
- Deletion
If not, what else do you base your selections upon? Is there any reference out there that lists how each container performs across all these different attributes?
Solution
+1 for effective STL.
But if you need an on-line reference, there is a good flowchart in StackOverflow Question 471432
OTHER TIPS
Scott Meyers' Effective STL covers not only this, but the weird pitfalls that you'll run into with some of the odder containers like set
.
Guarantee that the data is placed in continuous memory can be important. Typically if you are interested in using the data in the structure with interfaces that looks like doSomething(int* data, int dataCount).
I start of by thinking about the "shape" of the data, how often each item can repeat etc.