Roughing it with std::forward_list<T>
The standard container std::forward_list<T>
is a linked list like std::list
, but with fewer amenities--no way to get its size, no way to iterate backward. In memory it looks similar to std::list<T>
, but with smaller nodes:

Nevertheless, std::forward_list
retains almost all of the "special skills" of std::list
. The only operations that it can't do are splice
(because that involves inserting "before" the given iterator) and push_back
(because that involves finding the end of the list in constant time).
forward_list
replaces these missing member functions with _after
versions:
flst.erase_after(it)
to erase the element after the given positionflst.insert_after(it, v)
to insert a new element after the given positionflst.splice_after(it, otherflst)
to insert the elements ofotherflst
after the given position
As with std::list
, you should avoid using forward_list
at all unless you are in need of its particular set of skills.