13.3. std::forward_list

Like list, the forward_list is a container that stores elements in nodes A forward list only defines pointers to the next node in the list. This means that a forward list can only be traversed in the direction of the tail.

digraph list {
rankdir=LR;
node [fontname = "Bitstream Vera Sans", fontsize=14,
          style=filled, fillcolor=lightblue,
          shape=record];

head [shape=box];
a [label="{ <data> 8 | <ref>  }", width=1.2]
b [label="{ <data> 13 | <ref>  }"];
c [label="{ <data> 21 | <ref>  }"];
tail [shape=box];
head:e -> a:w     [arrowhead=vee];
a:ref:c -> b:data [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false, arrowsize=1.2];
b:ref:c -> c:data [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref:c -> tail:w [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
}

The defining operations of a std::forward_list are:

push_front

Add a new element to the beginning of the list.

pop_front

Remove an element from the beginning of the list.

front

Get the value of the element at the beginning of the list.

Compared to std::list this container provides more space efficient storage when bidirectional iteration is not needed. A very light-weight container, it does not have any overhead compared to its implementation in C.


You have attempted of activities on this page