Home | Projects | Notes > C++ Programming > Sequence Container - std::vector

Sequence Container - std::vector

 

std::vector

Initialization and Assignment

Common Methods

For more information, see cppreference.com.

capacity(): Returns the number of elements the vector can hold before needing to allocate more memory. When this capacity is exceeded, the vector expands dynamically.

max_size(): Returns the maximum number of elements a vector can theoretically hold on the current system. This is typically a very large number and depends on system and implementation limits.

L4: Remember, all standard container classes store copies of the elements they hold. So in this case, a copy of p is made.

L6: Creates a temporary (unnamed) person object and adds it to the vector using move semantics.

L7: Constructs the person object directly in place using the constructor. Very efficient - no moves, no copies. It’s built exactly where it needs to be. Use this!

 

Project: Usage of std::array