Home | Projects | Notes > C++ Programming > Sequence Container - std::list, std::forward_list

Sequence Container - std::list, std::forward_list

 

The STL Lists

 

std::list

 

list

 

Initialization and Assignment

Common Methods

For more information, see cppreference.com.

L17: The list will insert an element very efficiently before 3 and the it will still reference 3.

The std::list allows for efficiently inserting and deleting elements at the front and back:

 

std::forward_list (C++11)

 

forward_list

 

Initialization and Assignment

Common Methods

For more information, see cppreference.com.

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.

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

L8: 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::list

Ensure that your custom classes provide the following three elements to work correctly with the STL:

test3() in the following code demonstrates the importance of defining a default constructor for your custom class.