Home | Projects | Notes > C++ Programming > Introduction to STL Containers

Introduction to STL Containers

 

Containers

 

Common Methods of Containers

FunctionDescription
Default constructorInitializes an empty container
Overloaded constructorsInitializes containers with many options
Copy constructorInitializes a container as a copy of another container
Move constructorMoves existing container to new container
DestructorDestroys a container
Copy assignment (operator=)Copy one container to another
Move assignment (operator=)Move one container to another
sizeReturns the number of elements in the container
emptyReturns boolean - is the container empty?
insertInsert an element into the container
operator< and operator<=Returns boolean - compare contents of 2 containers
operator> and operator>=Returns boolean - compare contents of 2 containers
operator== and operator!=Returns boolean - are the contents of 2 containers equal or not
swapSwap the elements of 2 containers
eraseRemove element(s) from a container
clearRemove all elements from a container
begin and endReturns iterators to first element or end
rbegin and rendReturns reverse iterators to first element or end
cbegin and cendReturns constant iterators to first element or end
crbegin and crendReturns constant reverse iterators to first element or end

 

Types of Elements Containers Can Store

To ensure your custom objects work well with the STL, they should meet the following requirements: