Skip to main content

doubly_list_iterator Class Template

A class template for a doubly linked list iterator. More...

Declaration

template <class T, class N = T, class U = T>
class micro_os_plus::utils::doubly_list_iterator<T, N, U> { ... }

Included Headers

Public Member Typedefs Index

template <class T, class N = T, class U = T>
usingdifference_type = ptrdiff_t

Type of pointer difference. More...

template <class T, class N = T, class U = T>
usingiterator_category = std::bidirectional_iterator_tag

Category of iterator. More...

template <class T, class N = T, class U = T>
usingiterator_pointer = N *

Type of reference to the iterator internal pointer. More...

template <class T, class N = T, class U = T>
usingpointer = value_type *

Type of pointer to object pointed to by the iterator. More...

template <class T, class N = T, class U = T>
usingreference = value_type &

Type of reference to object pointed to by the iterator. More...

template <class T, class N = T, class U = T>
usingvalue_type = U

Type of value pointed to by the iterator. More...

Public Constructors Index

template <class T, class N = T, class U = T>
constexprdoubly_list_iterator () noexcept

Default constructor. Constructs an iterator pointing to nullptr. More...

template <class T, class N = T, class U = T>
constexprdoubly_list_iterator (iterator_pointer const node) noexcept

Construct an iterator from a node pointer. More...

template <class T, class N = T, class U = T>
constexprdoubly_list_iterator (reference element) noexcept

Construct an iterator from a reference to an element. More...

Public Operators Index

template <class T, class N = T, class U = T>
constexpr referenceoperator* () const noexcept

Dereference operator. More...

template <class T, class N = T, class U = T>
constexpr doubly_list_iterator &operator++ () noexcept

Pre-increment operator. More...

template <class T, class N = T, class U = T>
constexpr doubly_list_iteratoroperator++ (int) noexcept

Post-increment operator. More...

template <class T, class N = T, class U = T>
constexpr doubly_list_iterator &operator-- () noexcept

Pre-decrement operator. More...

template <class T, class N = T, class U = T>
constexpr doubly_list_iteratoroperator-- (int) noexcept

Post-decrement operator. More...

template <class T, class N = T, class U = T>
constexpr pointeroperator-> () const noexcept

Pointer access operator. More...

template <class T, class N = T, class U = T>
constexpr booloperator== (const doubly_list_iterator &other) const noexcept

Equality comparison operator. More...

Public Member Functions Index

template <class T, class N = T, class U = T>
constexpr iterator_pointerget_iterator_pointer (void) const noexcept

Get the internal iterator pointer (node pointer). More...

template <class T, class N = T, class U = T>
constexpr pointerget_pointer (void) const noexcept

Get a pointer to the value pointed to by the iterator. More...

Protected Member Attributes Index

template <class T, class N = T, class U = T>
iterator_pointernode_

Pointer to the node. More...

Description

A class template for a doubly linked list iterator.

Template Parameters
T

Type of object returned by the iterator.

N

Type of intrusive node. Must have the public members previous & next.

U

Type stored in the list, derived from T.

This iterator provides an interface similar to std::list::iterator for traversing a doubly linked list. It supports bidirectional iteration and access to the underlying node and value. In a typical doubly linked list, all types are doubly_list_links.

Definition at line 69 of file doubly-list.h.

Public Member Typedefs

difference_type

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::difference_type = ptrdiff_t

Type of pointer difference.

Definition at line 95 of file doubly-list.h.

95 using difference_type = ptrdiff_t;

iterator_category

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::iterator_category = std::bidirectional_iterator_tag

Category of iterator.

Definition at line 100 of file doubly-list.h.

100 using iterator_category = std::bidirectional_iterator_tag;

iterator_pointer

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::iterator_pointer = N*

Type of reference to the iterator internal pointer.

Definition at line 90 of file doubly-list.h.

90 using iterator_pointer = N*;

pointer

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::pointer = value_type*

Type of pointer to object pointed to by the iterator.

Definition at line 80 of file doubly-list.h.

reference

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::reference = value_type&

Type of reference to object pointed to by the iterator.

Definition at line 85 of file doubly-list.h.

value_type

template <class T, class N = T, class U = T>
using micro_os_plus::utils::doubly_list_iterator< T, N, U >::value_type = U

Type of value pointed to by the iterator.

Definition at line 75 of file doubly-list.h.

75 using value_type = U;

Public Constructors

doubly_list_iterator()

template <class T, class N = T, class U = T>
micro_os_plus::utils::doubly_list_iterator< T, N, U >::doubly_list_iterator ()
constexpr noexcept

Default constructor. Constructs an iterator pointing to nullptr.

The default constructor for doubly_list_iterator initialises the iterator to a null state, meaning it does not point to any node in the list. This is typically used to create an "end" iterator or to initialise an iterator variable before assigning it to a valid node.

info

The internal node pointer is value-initialised (set to nullptr), ensuring that the iterator is safe to use in comparisons and will not dereference an invalid address.

Declaration at line 108 of file doubly-list.h, definition at line 67 of file doubly-list-inlines.h.

68 : node_{}
69 {
70 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

Referenced by micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator==.

doubly_list_iterator()

template <class T, class N = T, class U = T>
micro_os_plus::utils::doubly_list_iterator< T, N, U >::doubly_list_iterator (iterator_pointer const node)
explicit constexpr noexcept

Construct an iterator from a node pointer.

Parameters
node

Pointer to the node to which the iterator should point.

This constructor creates a doubly_list_iterator that points to the specified node. The internal node pointer is set to the provided node address, allowing the iterator to traverse the list starting from that node. This constructor is typically used to initialise an iterator to a specific position within the list, such as the beginning or end.

Declaration at line 115 of file doubly-list.h, definition at line 81 of file doubly-list-inlines.h.

82 iterator_pointer const node) noexcept
83 : node_{ node }
84 {
85 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

doubly_list_iterator()

template <class T, class N = T, class U = T>
micro_os_plus::utils::doubly_list_iterator< T, N, U >::doubly_list_iterator (reference element)
explicit constexpr noexcept

Construct an iterator from a reference to an element.

Parameters
element

Reference to the element to which the iterator should point.

This constructor creates a doubly_list_iterator that points to the specified element. Since doubly_list elements are the nodes themselves (T derives from doubly_list_links_base), the internal node pointer is set to the address of the element directly. This is typically used to initialise an iterator to a specific object in the list.

Declaration at line 124 of file doubly-list.h, definition at line 96 of file doubly-list-inlines.h.

97 reference element) noexcept
98 : node_{ &element }
99 {
100 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

Public Operators

operator--()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U > & micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator-- ()
constexpr noexcept

Pre-decrement operator.

Returns

Reference to the decremented iterator.

The pre-decrement operator (operator--) moves the iterator to the previous node in the list. It updates the internal node pointer to point to the node returned by the current node's previous pointer. This enables backward traversal of the list, following the linked structure in reverse.

Declaration at line 167 of file doubly-list.h, definition at line 178 of file doubly-list-inlines.h.

179 {
180 node_ = static_cast<iterator_pointer> (node_->previous ());
181 return *this;
182 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

operator--()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U > micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator-- (int)
constexpr noexcept

Post-decrement operator.

Returns

Iterator before decrement.

The post-decrement operator (operator--(int)) moves the iterator to the previous node in the list, but returns a copy of the iterator as it was before the decrement. This enables iteration logic that requires access to the current element before moving backward, following the standard C++ iterator semantics for post-decrement.

Declaration at line 175 of file doubly-list.h, definition at line 194 of file doubly-list-inlines.h.

195 {
196 const auto tmp = *this;
197 node_ = static_cast<iterator_pointer> (node_->previous ());
198 return tmp;
199 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

operator->()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U >::pointer micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator-> ()
nodiscard constexpr noexcept

Pointer access operator.

Returns

Pointer to the value pointed to by the iterator.

The pointer access operator (operator->) allows the iterator to provide direct access to the value pointed to by the iterator, mimicking the behavior of a raw pointer. Internally, it calls get_pointer(), which computes and returns a pointer to the underlying value or object associated with the current node in the list.

Declaration at line 135 of file doubly-list.h, definition at line 112 of file doubly-list-inlines.h.

113 {
114 return get_pointer ();
115 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::get_pointer.

operator*()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U >::reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator* ()
nodiscard constexpr noexcept

Dereference operator.

Returns

Reference to the value pointed to by the iterator.

The dereference operator (operator*) provides access to the value or object pointed to by the iterator. Internally, it calls get_pointer() to obtain a pointer to the underlying value or object associated with the current node in the list, and then dereferences it to return a reference.

This allows the iterator to be used in a manner similar to standard C++ iterators, enabling direct access to the list element for reading or modification.

Declaration at line 143 of file doubly-list.h, definition at line 130 of file doubly-list-inlines.h.

131 {
132 return *get_pointer ();
133 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::get_pointer.

operator++()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U > & micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator++ ()
constexpr noexcept

Pre-increment operator.

Returns

Reference to the incremented iterator.

The pre-increment operator (operator++) advances the iterator to the next node in the list. It updates the internal node pointer to point to the node returned by the current node's next() method. This allows the iterator to traverse the list in the forward direction, following the linked structure.

Declaration at line 151 of file doubly-list.h, definition at line 145 of file doubly-list-inlines.h.

146 {
147 node_ = static_cast<N*> (node_->next ());
148 return *this;
149 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

operator++()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U > micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator++ (int)
constexpr noexcept

Post-increment operator.

Returns

Iterator before increment.

The post-increment operator (operator++(int)) advances the iterator to the next node in the list, but returns a copy of the iterator as it was before the increment. This allows iteration logic that requires access to the current element before moving to the next one, following the standard C++ iterator semantics for post-increment.

Declaration at line 159 of file doubly-list.h, definition at line 161 of file doubly-list-inlines.h.

162 {
163 const auto tmp = *this;
164 node_ = static_cast<iterator_pointer> (node_->next ());
165 return tmp;
166 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

operator==()

template <class T, class N = T, class U = T>
bool micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator== (const doubly_list_iterator & other)
nodiscard constexpr noexcept

Equality comparison operator.

Parameters
other

Iterator to compare with.

Returns

true if both iterators point to the same node, false otherwise.

info

The inequality operator (!=) is synthesised automatically by the compiler from this operator (C++20).

The equality comparison operator (operator==) checks whether two iterators point to the same node in the list by comparing their internal node pointers. This allows for standard iterator comparisons, such as detecting the end of a range or verifying if two iterators refer to the same position.

Declaration at line 189 of file doubly-list.h, definition at line 211 of file doubly-list-inlines.h.

212 const doubly_list_iterator& other) const noexcept
213 {
214 return node_ == other.node_;
215 }

References micro_os_plus::utils::doubly_list_iterator< T, N, U >::doubly_list_iterator and micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

Public Member Functions

get_iterator_pointer()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U >::iterator_pointer micro_os_plus::utils::doubly_list_iterator< T, N, U >::get_iterator_pointer (void)
nodiscard constexpr noexcept

Get the internal iterator pointer (node pointer).

Parameters

None.

Returns

Pointer to the node.

Returns the internal node pointer that the iterator currently references. This is useful for advanced list operations or when direct access to the underlying node structure is required, such as for interoperability with other list utilities or for debugging purposes.

Declaration at line 209 of file doubly-list.h, definition at line 226 of file doubly-list-inlines.h.

227 {
228 return node_;
229 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

get_pointer()

template <class T, class N = T, class U = T>
doubly_list_iterator< T, N, U >::pointer micro_os_plus::utils::doubly_list_iterator< T, N, U >::get_pointer (void)
nodiscard constexpr noexcept

Get a pointer to the value pointed to by the iterator.

Parameters

None.

Returns

Pointer to the value.

Returns the node pointer cast to the value pointer type. In the typical usage where all three template parameters are the same type (T, N, U all equal), this is a trivial static cast.

Declaration at line 199 of file doubly-list.h, definition at line 239 of file doubly-list-inlines.h.

240 {
241 return static_cast<pointer> (node_);
242 }

Reference micro_os_plus::utils::doubly_list_iterator< T, N, U >::node_.

Referenced by micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator* and micro_os_plus::utils::doubly_list_iterator< T, N, U >::operator->.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.