Skip to main content

intrusive_list_iterator Class Template

A class template for the intrusive list iterator. More...

Declaration

template <class T, class N, N T::* MP, class U = T> class micro_os_plus::utils::intrusive_list_iterator<T, N, MP, U> { ... }

Included Headers

Public Member Typedefs Index

template <class T, class N, N T::* MP, class U = T>
usingdifference_type = ptrdiff_t

Type of pointer difference. More...

template <class T, class N, N T::* MP, class U = T>
usingiterator_category = std::forward_iterator_tag

Category of iterator. More...

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

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

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

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

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

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

template <class T, class N, N T::* MP, class U = T>
usingvalue_type = U

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

Public Constructors Index

template <class T, class N, N T::* MP, class U = T>
constexprintrusive_list_iterator ()

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

template <class T, class N, N T::* MP, class U = T>
constexprintrusive_list_iterator (iterator_pointer const node)

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

template <class T, class N, N T::* MP, class U = T>
constexprintrusive_list_iterator (reference element)

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

Public Operators Index

template <class T, class N, N T::* MP, class U = T>
booloperator!= (const intrusive_list_iterator &other) const

Inequality comparison operator. More...

template <class T, class N, N T::* MP, class U = T>
referenceoperator* () const

Dereference operator. More...

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator &operator++ ()

Pre-increment operator. More...

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iteratoroperator++ (int)

Post-increment operator. More...

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator &operator-- ()

Pre-decrement operator. More...

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iteratoroperator-- (int)

Post-decrement operator. More...

template <class T, class N, N T::* MP, class U = T>
pointeroperator-> () const

Pointer access operator. More...

template <class T, class N, N T::* MP, class U = T>
booloperator== (const intrusive_list_iterator &other) const

Equality comparison operator. More...

Public Member Functions Index

template <class T, class N, N T::* MP, class U = T>
iterator_pointerget_iterator_pointer (void) const

Retrieve the iterator pointer for the current node. More...

template <class T, class N, N T::* MP, class U = T>
pointerget_pointer (void) const

Get the object node from the intrusive node. More...

Protected Member Attributes Index

template <class T, class N, N T::* MP, class U = T>
iterator_pointernode_

Pointer to intrusive node. More...

Description

A class template for the intrusive list iterator.

Template Parameters
T

Type of object that includes the intrusive node.

N

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

MP

Name of the intrusive node member in object T.

U

Type stored in the list, derived from T.

This class provides an interface similar to std::list::iterator, except that it keeps track of the offset where the intrusive list element is located in the parent object. It supports bidirectional iteration and access to the underlying object and node.

Definition at line 933 of file lists.h.

Public Member Typedefs

difference_type

template <class T, class N, N T::* MP, class U = T>
using micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::difference_type = ptrdiff_t

Type of pointer difference.

Definition at line 959 of file lists.h.

959 using difference_type = ptrdiff_t;

iterator_category

template <class T, class N, N T::* MP, class U = T>
using micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::iterator_category = std::forward_iterator_tag

Category of iterator.

Definition at line 964 of file lists.h.

964 using iterator_category = std::forward_iterator_tag;

iterator_pointer

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

Type of reference to the iterator internal pointer.

Definition at line 954 of file lists.h.

954 using iterator_pointer = N*;

pointer

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

Type of pointer to object pointed to by the iterator.

Definition at line 944 of file lists.h.

reference

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

Type of reference to object pointed to by the iterator.

Definition at line 949 of file lists.h.

value_type

template <class T, class N, N T::* MP, class U = T>
using micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::value_type = U

Type of value pointed to by the iterator.

Definition at line 939 of file lists.h.

939 using value_type = U;

Public Constructors

intrusive_list_iterator()

template <class T, class N, N T::* MP, class U = T>
micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::intrusive_list_iterator ()
constexpr

Default constructor. Constructs an iterator pointing to nullptr.

The default constructor for intrusive_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 972 of file lists.h, definition at line 735 of file lists-inlines.h.

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

Referenced by micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator!= and micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator==.

intrusive_list_iterator()

template <class T, class N, N T::* MP, class U = T>
micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::intrusive_list_iterator (iterator_pointer const node)
explicit constexpr

Construct an iterator from a node pointer.

Parameters
node

Pointer to the node to which the iterator should point.

This constructor creates an intrusive_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 is typically used to initialise an iterator to a specific position within the list, such as the beginning or end.

Declaration at line 979 of file lists.h, definition at line 749 of file lists-inlines.h.

750 N* const node)
751 : node_{ node }
752 {
753 }

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

intrusive_list_iterator()

template <class T, class N, N T::* MP, class U = T>
micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::intrusive_list_iterator (reference element)
explicit constexpr

Construct an iterator from a reference to an element.

Parameters
element

Reference to the element to which the iterator should point.

This constructor creates an intrusive_list_iterator that points to the specified element. The internal node pointer is set to the address of the intrusive node member within the given element, allowing the iterator to traverse the list starting from that element. This is typically used to initialise an iterator to a specific object in the list.

Declaration at line 987 of file lists.h, definition at line 764 of file lists-inlines.h.

765 reference element)
766 : node_{ &(element.*MP) }
767 {
768 static_assert (std::is_convertible<U, T>::value == true,
769 "U must be implicitly convertible to T!");
770 }

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

Public Operators

operator--()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U > & micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator-- ()
inline

Pre-decrement operator.

Returns

Reference to the decremented iterator.

The pre-decrement operator (operator--) moves the intrusive list 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() method. This enables backward traversal of the list, following the linked structure in reverse.

Declaration at line 1030 of file lists.h, definition at line 848 of file lists-inlines.h.

849 {
850 node_ = static_cast<iterator_pointer> (node_->previous ());
851 return *this;
852 }

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

operator--()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U > micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator-- (int)

Post-decrement operator.

Returns

Iterator before decrement.

The post-decrement operator (operator--(int)) moves the intrusive list 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 1038 of file lists.h, definition at line 864 of file lists-inlines.h.

865 {
866 const auto tmp = *this;
867 node_ = static_cast<iterator_pointer> (node_->previous ());
868 return tmp;
869 }

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

operator->()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U >::pointer micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator-> ()
inline

Pointer access operator.

Returns

Pointer to the value pointed to by the iterator.

The pointer access operator (operator->) allows the intrusive list 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 998 of file lists.h, definition at line 782 of file lists-inlines.h.

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

operator!=()

template <class T, class N, N T::* MP, class U = T>
bool micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator!= (const intrusive_list_iterator & other)
inline

Inequality comparison operator.

Parameters
other

Iterator to compare with.

Returns

true if the iterators point to different nodes, false otherwise.

The inequality comparison operator (operator!=) checks whether two intrusive list iterators point to different nodes in the list by comparing their internal node pointers. This is useful for standard iterator operations, such as determining whether an iterator has reached the end of a range or for loop termination conditions.

Declaration at line 1057 of file lists.h, definition at line 897 of file lists-inlines.h.

898 const intrusive_list_iterator& other) const
899 {
900 return node_ != other.node_;
901 }

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

operator*()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U >::reference micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator* ()
inline

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 1006 of file lists.h, definition at line 800 of file lists-inlines.h.

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

operator++()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U > & micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator++ ()
inline

Pre-increment operator.

Returns

Reference to the incremented iterator.

The pre-increment operator (operator++) advances the intrusive list 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 enables forward traversal of the list, following the linked structure.

Declaration at line 1014 of file lists.h, definition at line 815 of file lists-inlines.h.

816 {
817 node_ = static_cast<iterator_pointer> (node_->next ());
818 return *this;
819 }

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

operator++()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U > micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator++ (int)
inline

Post-increment operator.

Returns

Iterator before increment.

The post-increment operator (operator++(int)) advances the intrusive list 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 1022 of file lists.h, definition at line 831 of file lists-inlines.h.

832 {
833 const auto tmp = *this;
834 node_ = static_cast<iterator_pointer> (node_->next ());
835 return tmp;
836 }

operator==()

template <class T, class N, N T::* MP, class U = T>
bool micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::operator== (const intrusive_list_iterator & other)
inline

Equality comparison operator.

Parameters
other

Iterator to compare with.

Returns

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

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

Declaration at line 1048 of file lists.h, definition at line 881 of file lists-inlines.h.

882 const intrusive_list_iterator& other) const
883 {
884 return node_ == other.node_;
885 }

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

Public Member Functions

get_iterator_pointer()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U >::iterator_pointer micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::get_iterator_pointer (void)
inline

Retrieve the iterator pointer for the current node.

Parameters

None.

Returns

The iterator pointer corresponding to the current node.

Returns a pointer to the internal iterator node associated with the current object. This is typically used for advanced list operations or when direct access to the underlying node is required.

Declaration at line 1077 of file lists.h, definition at line 938 of file lists-inlines.h.

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

get_pointer()

template <class T, class N, N T::* MP, class U = T>
intrusive_list_iterator< T, N, MP, U >::pointer micro_os_plus::utils::intrusive_list_iterator< T, N, MP, U >::get_pointer (void)
inline

Get the object node from the intrusive node.

Parameters

None.

Returns

Pointer to object node.

Computes and returns a pointer to the parent object that contains the intrusive node currently referenced by the iterator. This is achieved by calculating the offset of the intrusive node member within the parent object type and subtracting it from the node's address. This technique allows the iterator to provide access to the full object from just the node pointer, enabling intrusive list traversal and manipulation.

Declaration at line 1067 of file lists.h, definition at line 914 of file lists-inlines.h.

915 {
916 // static_assert(std::is_convertible<U, T>::value == true, "U must be
917 // implicitly convertible to T!");
918
919 // Compute the distance between the member intrusive link
920 // node and the class begin.
921 const auto offset = reinterpret_cast<difference_type> (
922 &(static_cast<T*> (nullptr)->*MP));
923
924 // Compute the address of the object which includes the
925 // intrusive node, by adjusting down the node address.
926 return reinterpret_cast<pointer> (reinterpret_cast<difference_type> (node_)
927 - offset);
928 }

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

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


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.