containers
std::vector<int> ports{22, 80, 443};
ports.push_back(8080);
std::sort(ports.begin(), ports.end());
vector
The default sequence container Contiguous memory, fast iteration, expensive insertion in the middle Reserve when you know the count to avoid repeated reallocation
array
std::array is a fixed size container
No heap allocation
Size is part of the type
map and unordered_map
map keeps keys ordered
unordered_map uses hashing and gives average constant time lookup
Choose by access pattern, not by habit
string_view
Borrowed text
Cheap to pass around
Dangerous when it outlives the owner
If the lifetime is not obvious, use std::string
Next
Algorithms in 09 algorithms
Posted