Item1: Choose your containers with care
The foundation of how to choose your containers is the characteristics of those containers, the following question quoted from the book can give you some clues.
1. Do you need to be able to insert a new element at an arbitrary position in the container?
2. Do you care how elements are ordered in the container?
3. Must the container be part of standard C++?
4. What category of iterators do you require?
5. Is it important to avoid movement of existing container elements when insertions or erasures take place?
6. Does the data in the container need to be layout-compatible with C?
7. Is lookup speed a critical consideration?
8. Do you mind if the underlying container uses reference counting?
9. Do you need transactional semantics for insertions and erasures?
10.Do you need to minimize iterator, pointer, and reference invalidation?
11.Would it be helpful to have a sequence container with random access iterators where pointers and references to the data are not invalidated as long as nothing is erased and insertions take place only at the ends of the container?
I think these are just parts, but important parts of those what you should consider. And let's start from here...
1. Do you need to be able to insert a new element at an arbitrary position in the container?
2. Do you care how elements are ordered in the container?
3. Must the container be part of standard C++?
4. What category of iterators do you require?
5. Is it important to avoid movement of existing container elements when insertions or erasures take place?
6. Does the data in the container need to be layout-compatible with C?
7. Is lookup speed a critical consideration?
8. Do you mind if the underlying container uses reference counting?
9. Do you need transactional semantics for insertions and erasures?
10.Do you need to minimize iterator, pointer, and reference invalidation?
11.Would it be helpful to have a sequence container with random access iterators where pointers and references to the data are not invalidated as long as nothing is erased and insertions take place only at the ends of the container?
I think these are just parts, but important parts of those what you should consider. And let's start from here...

浙公网安备 33010602011771号