Forward Lists
std::forward_list
is a singly linked list, which needs the header <forward_list>
. std::forward_list
has a drastically reduced interface and is optimised for minimal memory requirements.
std::forward_list
has a lot in common with std::list
:
- It supports no random access.
- The access of an arbitrary element is slow because in the worst case you 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 you add or remove an element, the iterator keeps valid.
- Operations always refer to the beginning of the
std::forward_list
or the position past the current element.
The characteristic that you can iterator a std::forward_list
forward has a great impact. So the iterators cannot be decremented and therefore, operations like It--
on iterators are not supported. For the same reason, std::forward_list
has no backward iterator. std::forward_list
is the only sequential container...