Lumiera  0.pre.03
»edit your freedom«
linked-elements.hpp File Reference

Go to the source code of this file.

Description

Intrusive single linked list with optional ownership.

This helper template allows to attach a number of tightly integrated elements with low overhead. Typically, these elements are to be attached once and never changed. Optionally, elements can be created using a custom allocation scheme; the holder might also take ownership. These variations in functionality are controlled by policy templates.

The rationale for using this approach is

  • variable number of elements
  • explicit support for polymorphism
  • no need to template the holder on the number of elements
  • no heap allocations (contrast this to using std::vector)
  • clear and expressive notation at the usage site
  • convenient access through Lumiera Forward Iterators
  • the need to integrate tightly with a custom allocator
Note
this linked list container is intrusive and thus needs the help of the element type, which must provide a pointer member next. Consequently, each such node element can't be member in multiple collections at the same time
as usual, any iterator relies on the continued existence and unaltered state of the container. There is no sanity check.
Warning
this container is deliberately not threadsafe
be sure to understand the implications of taking ownership: When adding an existing node element (by pointer) to a LinkedElements list which takes ownership, the list will attempt to destroy or de-allocate this node element when going out of scope.
See also
LinkedElements_test
llist.h
ScopedCollection
itertools.hpp

Definition in file linked-elements.hpp.

#include "lib/error.hpp"
#include "lib/nocopy.hpp"
#include "lib/iter-adapter.hpp"
#include "lib/util.hpp"
#include <utility>

Classes

struct  LinkedElements< N, ALO >::IterationState
 Iteration is just following the single linked list. More...
 
class  LinkedElements< N, ALO >
 Intrusive single linked list, possibly taking ownership of node elements. More...
 
struct  NoOwnership
 Policy for LinkedElements: never create or destroy any elements, only allow to add already existing nodes. More...
 
struct  OwningHeapAllocated
 < allocation policies for the LinkedElements list container More...
 

Namespaces

 lib
 Implementation namespace for support and library code.