Lumiera  0.pre.03
»edit your freedom«
LinkedElements< N, ALO > Class Template Reference

#include "lib/linked-elements.hpp"

Description

template<class N, class ALO = linked_elements::OwningHeapAllocated<N>>
class lib::LinkedElements< N, ALO >

Intrusive single linked list, possibly taking ownership of node elements.

Additional elements can be pushed (prepended) to the list; element access is per index number (slow) or through an Lumiera Forward Iterator traversing the linked list. There is no support for changing the list contents aside of discarding any element in the list.

The allocation and ownership related behaviour is controlled by a policy class provided as template parameter. When this policy supports creation of new elements, these might be created and prepended in one step.

Note
with the default policy, sizeof(LinkedElements) == sizeof(N*)

Definition at line 158 of file linked-elements.hpp.

Public Types

using const_iterator = IterStateWrapper< IterationState, const N & >
 
using iterator = IterStateWrapper< IterationState, N & >
 

Public Member Functions

 LinkedElements (LinkedElements const &)=default
 
 LinkedElements (LinkedElements &&rr)
 
 LinkedElements (typename ALO::CustomAllocator allo)
 
template<class IT >
 LinkedElements (IT &&elements)
 creating a LinkedElements list in RAII-style: More...
 
iterator begin ()
 
const_iterator begin () const
 
void clear () noexcept
 
template<class TY = N, typename... ARGS>
TY & emplace (ARGS &&...args)
 prepend object of type TY, forwarding ctor args
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
N & operator[] (size_t index) const
 
template<typename TY >
TY & push (TY &elm) noexcept
 accept the given element and prepend it to the list of elements; depending on the allocation policy, this might imply taking ownership More...
 
template<class IT >
void pushAll (IT elements)
 convenience shortcut to add all the elements yielded by the given Lumiera Forward Iterator More...
 
LinkedElementsreverse ()
 Mutate the complete list to change the order of elements. More...
 
size_t size () const
 
N & top () const
 

Classes

struct  IterationState
 Iteration is just following the single linked list. More...
 

Private Attributes

N * head_
 

Constructor & Destructor Documentation

◆ LinkedElements() [1/2]

LinkedElements ( typename ALO::CustomAllocator  allo)
inlineexplicit
Parameters
allocustom allocator or memory manager to be used by the policy for creating and discarding of node elements

Definition at line 187 of file linked-elements.hpp.

◆ LinkedElements() [2/2]

LinkedElements ( IT &&  elements)
inline

creating a LinkedElements list in RAII-style:

Parameters
elementsiterator to provide all the elements to be pushed into this newly created collection
Note
any exception while populating the container causes already created elements to be destroyed

Definition at line 200 of file linked-elements.hpp.

Member Function Documentation

◆ clear()

void clear ( )
inlinenoexcept
Note
EX_FREE

Definition at line 218 of file linked-elements.hpp.

◆ pushAll()

void pushAll ( IT  elements)
inline

convenience shortcut to add all the elements yielded by the given Lumiera Forward Iterator

Note
EX_SANE

Definition at line 238 of file linked-elements.hpp.

◆ push()

TY& push ( TY &  elm)
inlinenoexcept

accept the given element and prepend it to the list of elements; depending on the allocation policy, this might imply taking ownership

Note
EX_STRONG

Definition at line 253 of file linked-elements.hpp.

◆ reverse()

LinkedElements& reverse ( )
inline

Mutate the complete list to change the order of elements.

Remarks
since pushing prepends, elements are initially in reverse order
Warning
this operation invalidates iterators and has O(n) cost; ownership and elements themselves are not affected.

Definition at line 279 of file linked-elements.hpp.

◆ top()

N& top ( ) const
inline
Warning
unchecked

Definition at line 319 of file linked-elements.hpp.

◆ size()

size_t size ( ) const
inline
Warning
traverses to count the elements

Definition at line 328 of file linked-elements.hpp.

+ Inheritance diagram for LinkedElements< N, ALO >:
+ Collaboration diagram for LinkedElements< N, ALO >:

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