|
-
January 16th, 2012, 03:15 PM
#4
Re: best std container class for my application?
Do you want to add a new object in the middle of the container?
If yes, you could consider deque std: eque or std::list. Otherwise I would suggest std::vector. For 1. you would could do a simple loop over the entire container to look for the id. The efficiency could be improved by keeping the container sorted, but then...
There are containers that will do the sorting for you as soon as elements are added:
std::map and std::set are 'automatically' sorted, but they only keep unique keys/elements resp.. If you dont want to keep duplicate CTestObjects, then std::set will work well for you. If you do need to consider duplicates, then look at std::multimap, or suggestions in previous paragraph.
If you use one of the former suggestions, you could use std::find, or manually loop over the container yourself. Or sort and then use binary_search.
If you use a map or a set, you can use their member method find(...)
Last edited by Amleto; January 16th, 2012 at 03:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|