LEARN BY DOING
C++ container chooser
Describe your access and storage constraints. See a suitable starting point and the contract you still need to check.
Describe the workload
This is a starting point for the named operations. Element types, allocators and measured workload can change the final choice.
A CONTRACT TO CONSIDER
std::vector<T>
An owning, growable sequence with contiguous storage and random access.
Operations & cost
Amortized constant-time append; middle insertion and erasure are linear.
Check the lifetime contract
Reallocation invalidates pointers, references and iterators. reserve() only avoids reallocation while size remains within capacity; insertion and erasure have additional invalidation rules.