FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
containers::LinkedList< T_ > Class Template Reference

Linked list of type T_ items. More...

#include <fastarduino/linked_list.h>

Inheritance diagram for containers::LinkedList< T_ >:
Collaboration diagram for containers::LinkedList< T_ >:

Public Types

using T = T_
 The type of items in this list.
 

Public Member Functions

 LinkedList (const LinkedList< T_ > &)=default
 
LinkedList< T_ > & operator= (const LinkedList< T_ > &)=delete
 
void insert (T &item) INLINE
 Insert item at the beginning of this list. More...
 
bool remove (T &item) INLINE
 Remove item from this list. More...
 
template<typename F >
void traverse (F func)
 Traverse all items of this list and execute f functor. More...
 

Detailed Description

template<typename T_>
class containers::LinkedList< T_ >

Linked list of type T_ items.

This list offers 3 operations:

  • insert a new item (at the beginning of the list)
  • remove any item from the list (O(n))
  • traverse all items of the list and execute a function on each

For the sake of SRAM size optimization, the list is not double linked.

A concrete example of LinkedList use in FastArduino API can be found in events::Dispatcher.

Template Parameters
T_the type of items stored in the list; this must be a Link<T>.
See also
Link

Definition at line 80 of file linked_list.h.

Member Function Documentation

◆ insert()

template<typename T_ >
void containers::LinkedList< T_ >::insert ( T item)
inline

Insert item at the beginning of this list.

Note that item is not copied by the list, only a reference is kept, thus it is caller's responsibility to ensure that item will live at least as long as this list lives.

Parameters
itema reference to the inserted item
See also
remove()

Definition at line 106 of file linked_list.h.

◆ remove()

template<typename T_ >
bool containers::LinkedList< T_ >::remove ( T item)
inline

Remove item from this list.

The item is first searched in the list (from the beginning to the end), and removed if found. Note that search is based on item reference (i.e. pointer), not content.

Parameters
itema reference of the item to remove
Return values
trueif item was found in this list and removed
falseif item was not found in this list

Definition at line 121 of file linked_list.h.

◆ traverse()

template<typename T_ >
template<typename F >
void containers::LinkedList< T_ >::traverse ( F  func)
inline

Traverse all items of this list and execute f functor.

Template Parameters
Fthe functor type: this type may just be a function pointer or a class overloading operator(); in any case, it is passed a reference to a T item and must return a bool; if it returns true for a given item, then that item will be removed from this list.
Parameters
functhe functor to execute on each item

Definition at line 135 of file linked_list.h.


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