#include <forwardlist.hpp>
This is a generic base type that represents a node of a single linked lists. The effective (instantiated) nodes of the list are to be derived from this type with specifying their very own type name as template parameter TElement. The following quick sample demonstrates this:
This documentation, as well as the documentation of types ForwardList and ForwardListIterator, uses the terms "node" for this type and "element" for the custom derived type TElement that contains the custom (container) data.
With this simple mechanism in place, node instances may be used as "anchors" to the first element of a list. Pointers to nodes of this type may either point to a node or to an element. Instances of nodes always point to an element instance.
While pointers to nodes and elements are statically castable to each other (which is a "noop" because it does not change the pointer's address on common platforms/compilers), most methods accept and/or return pointers to derived type TElement, and if so, it has to be assured by the caller that the input parameters in fact point to those derived instances. Likewise it is assured by this type and types ForwardList and ForwardListIterator, that a returned pointer to an element does so.
This "contract" provides maximum type safety while dealing with start pointers to element lists (which are usually non-castable instances of this base type as provided with ForwardList), while avoiding the need of code clutter by inserting static_cast to TElement in the using code as much as possible. Furthermore, this concept allows to have field forward of type TElement which makes debugging much easier, because the custom values of the derived types are always visible.
| TElement | The "final" node type, containing custom data fields, that is to be derived from this struct. |
Definition at line 75 of file forwardlist.hpp.
Public Types | |
| using | ConstIterator = ForwardListIterator< const TElement > |
| using | Iterator = ForwardListIterator< TElement > |
| using | TNode = ForwardNode< TElement > |
Public Static Methods | |
| static integer | count (TElement *start, TElement *end=nullptr) |
| static void | moveForward (TElement *&pointer) |
| static TElement * | moveForward (TNode *&pointer) |
Public Methods | |
| ForwardNode () noexcept=default | |
| ForwardNode (const TNode &)=delete | |
| ForwardNode (TElement *next) noexcept | |
| ForwardNode (TNode &&) noexcept=default | |
| TElement * | addBehind (TElement *elem) |
| TElement * | addBehind (TElement *first, TElement *last) |
| Iterator | begin () |
| ConstIterator | begin () const |
| ConstIterator | cbegin () const |
| ConstIterator | cend () const |
| Iterator | end () |
| ConstIterator | end () const |
| bool | hasNext () const |
| bool | isLast () const |
| TElement * | makeLast () |
| TElement * | makePointTo (TElement *elem) |
| TElement * | next () const |
| ForwardNode & | operator= (const TNode &)=delete |
| ForwardNode & | operator= (TNode &&) noexcept=default |
| bool | pointsTo (TElement *elem) const |
| TElement * | removeNext () |
| TElement * | removeRangeBehind (TElement *last) |
Private Fields | |
| TElement * | forward |
| using ConstIterator = ForwardListIterator<const TElement> |
The constant std::iterator type.
Definition at line 235 of file forwardlist.hpp.
| using Iterator = ForwardListIterator<TElement> |
The mutable std::iterator type.
Definition at line 232 of file forwardlist.hpp.
| using TNode = ForwardNode<TElement> |
Alias name for the an instantiation of this template.
Definition at line 86 of file forwardlist.hpp.
|
defaultnoexcept |
Default constructor. (Does not initialize the pointer!)
|
delete |
Deleted copy constructor. This is deleted because it is dangerous, respectively often not possible and also mostly not wanted to be able to create copies of derived type TElement
|
defaultnoexcept |
Defaulted move constructor.
|
inlinenoexcept |
Constructor accepting a pointer to the next element.
| next | Pointer to the next element. Assigned to field forward. |
Definition at line 121 of file forwardlist.hpp.
|
inline |
Hooks the given element behind this node or element.
| elem | The element to insert behind this node or element. |
Definition at line 207 of file forwardlist.hpp.
|
inline |
Hooks the given range of elements behind this node or element.
| first | The first element of the range to insert. |
| last | The last element of the range to insert. |
Definition at line 220 of file forwardlist.hpp.
|
inline |
Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.
Definition at line 240 of file forwardlist.hpp.
|
inline |
Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.
Definition at line 249 of file forwardlist.hpp.
|
inline |
Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.
Definition at line 258 of file forwardlist.hpp.
|
inline |
Returns an iterator referring to the end of a range of elements (aka a nullptr).
Definition at line 262 of file forwardlist.hpp.
|
inlinestatic |
Counts the number of elements found in the range starting with start and ending with the element before end.
| start | Pointer to the first element to count. |
| end | Pointer to the element after the last one to count. Defaults to nullptr, marking the end of a list. |
Definition at line 274 of file forwardlist.hpp.
|
inline |
Returns an iterator referring to the end of a range of elements (aka a nullptr).
Definition at line 244 of file forwardlist.hpp.
|
inline |
Returns an iterator referring to the end of a range of elements (aka a nullptr).
Definition at line 253 of file forwardlist.hpp.
|
inline |
Test if this node or element has a next element linked.
false if field forward equals nullptr, otherwise true. Definition at line 135 of file forwardlist.hpp.
|
inline |
Test if this element is the last element of the list.
true if field forward equals nullptr, otherwise false. Definition at line 128 of file forwardlist.hpp.
|
inline |
Sets field forward to nullptr.
Definition at line 150 of file forwardlist.hpp.
|
inline |
Sets field forward to elem.
| elem | The element that this node or element is to point to. |
Definition at line 160 of file forwardlist.hpp.
|
inlinestatic |
Moves the given element pointer reference to point to the next element.
| pointer | A reference to the pointer to move forward. |
Definition at line 300 of file forwardlist.hpp.
|
inlinestatic |
Moves the given node pointer reference to point to the next node. The result is the moved pointer, casted to an element.
| pointer | A reference to the pointer to move forward. |
Definition at line 290 of file forwardlist.hpp.
|
inline |
Returns the successor of this node or element.
nullptr if this is the last element of the list. Definition at line 171 of file forwardlist.hpp.
|
delete |
Deleted copy assignment operator. This is deleted because it is dangerous, respectively often not possible and also mostly not wanted to created copies of derived type TElement
|
defaultnoexcept |
Defaulted move assignment operator.
|
inline |
Test if elem is the successor fo this node or element.
| elem | The element to test for being a successor of this. |
true if field forward equals elem , otherwise false. Definition at line 143 of file forwardlist.hpp.
|
inline |
Unhooks and returns the element after this node or element.
nullptr.Definition at line 181 of file forwardlist.hpp.
|
inline |
Unhooks successors until last. If last equals field forward, only one element is unhooked.
nullptr.| last | The last element of the range [forward, last] which is removed. |
Definition at line 197 of file forwardlist.hpp.
|
private |
In case of derived type TElement this is the pointer to the next element. In case of derived class ForwardList, this is the pointer to the first element of the list.
Definition at line 93 of file forwardlist.hpp.