Search⌘ K

Forward Lists

Explore the features and usage of std forward_list in C++ sequential containers. Understand its memory optimization, performance benefits, and unique methods for element manipulation, such as emplace_after and merge, to efficiently manage singly linked lists.

We'll cover the following...

std::forward_list is a singly linked list, which needs the header <forward_list>. std::forward_list has a drastically reduced interface and is optimized for minimal memory requirements.

std::forward_list has a lot in common with std::list:

  • It doesn’t support the random access.
  • The access of an arbitrary element is slow because in the worst case, we have to iterate forward through the whole list.
  • To add or remove an element is fast, if the iterator points to the right place.
  • If we add or
...