template<class Derived, class List = LinkedList<Derived>>
Corrade::Containers::LinkedListItem class

Item of LinkedList.

Template parameters
Derived Dervied object type, i.e. type you want returned from previous() and next().
List List object type, i.e. type you want returned from list().

This class is usually subclassed using CRTP, e.g.:

class Item: public Containers::LinkedListItem<Item> {
    // ...
};

See LinkedList for more information.

Constructors, destructors, conversion operators

LinkedListItem() noexcept
Default constructor.
LinkedListItem(const LinkedListItem<Derived, List>&) deleted
Copying is not allowed.
LinkedListItem(LinkedListItem<Derived, List>&& other)
Move constructor.
~LinkedListItem() pure virtual
Destructor.

Public functions

auto operator=(const LinkedListItem<Derived, List>&) -> LinkedListItem<Derived, List>& deleted
Copying is not allowed.
auto operator=(LinkedListItem<Derived, List>&& other) -> LinkedListItem<Derived, List>&
Move assignment.
auto list() -> List*
List this item belongs to.
auto list() const -> const List*
auto previous() -> Derived*
Previous item or nullptr, if there is no previous item.
auto previous() const -> const Derived*
auto next() -> Derived*
Next item or nullptr, if there is no next item.
auto next() const -> const Derived*
void erase()
Erase the item.

Private functions

void doErase() virtual
Erase the item.

Function documentation

template<class Derived, class List>
Corrade::Containers::LinkedListItem<Derived, List>::LinkedListItem() noexcept

Default constructor.

Creates item not connected to any list.

template<class Derived, class List>
Corrade::Containers::LinkedListItem<Derived, List>::~LinkedListItem() pure virtual

Destructor.

If the item is part of any list, it is removed from it.

template<class Derived, class List>
const List* Corrade::Containers::LinkedListItem<Derived, List>::list() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Derived, class List>
const Derived* Corrade::Containers::LinkedListItem<Derived, List>::previous() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Derived, class List>
const Derived* Corrade::Containers::LinkedListItem<Derived, List>::next() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Derived, class List>
void Corrade::Containers::LinkedListItem<Derived, List>::erase()

Erase the item.

Called from LinkedList destructor, LinkedList::clear() and LinkedList::erase(). By default, calls doErase(), which then calls LinkedList::cut() followed by delete this. For cases where this is not desired (for example when providing bindings to reference-counted languages), it's possible to provide a different behavior by either:

  • replacing this non-virtual function in your derived class (faster, doesn't involve a virtual call, but requires the corresponding LinkedList to be templated on the type that provides the replacement function),
  • or overriding the private doErase() function (slower due to the virtual call, but without imposing any restrictions on the LinkedList type)

The overriden implementation has to call LinkedList::cut() in order to correctly remove itself from the list; the list() is guaranteed to be non- nullptr in this context.

template<class Derived, class List>
void Corrade::Containers::LinkedListItem<Derived, List>::doErase() virtual private

Erase the item.

Implementation for erase(), see its documentation for more information. Default implementation calls LinkedList::cut() followed by delete this.