Template Class forward_list
Defined in File forward_list.hpp
Nested Relationships
Nested Types
Class Documentation
-
template<typename T, uint64_t Capacity>
class forward_list C++11 compatible uni-directional forward list implementation.
Adjustments in the API were done to not use exceptions and serve the requirement of a data structure movable over shared memory. attempt to add elements to a full list will be ignored. Capacity must at least be 1, (unintended) negative initialization is rejected with compile assertion limitation: concurrency concerns have to be handled by client side.
overview of cxx::forward_list deviations to std::forward_list(C++11)
list declaration with mandatory max list size argument
member functions don’t throw exception but will trigger different failure handling
push_front returns a bool (instead of void) informing on successful insertion (true)
pop_front returns a bool (instead of void) informing on successful removal (true), otherwise empty (false)
emplace_front returns a reference to the inserted element (instead of void), this is C++17-conform
remove / remove_if returns a the number of removed elements (instead of void), this is C++20-conform
Public Functions
-
forward_list() noexcept
constructor for an empty list (of T-types elements)
-
~forward_list() noexcept
destructs the list and also calls the destructor of all contained elements
-
forward_list(const forward_list &rhs) noexcept
copy constructor list including elements
- Parameters:
rhs – [in] is the list to copy from (same capacity)
-
forward_list(forward_list &&rhs) noexcept
move constructor list including elements
- Parameters:
rhs – [in] is the list to move-construct elements from (same capacity)
-
forward_list &operator=(const forward_list &rhs) noexcept
copy assignment, each element is copied (added) to the constructed list any existing elements in ‘this’/lhs are removed (same behaviour as std::list : Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.)
- Parameters:
rhs – [in] is the list to copy from (same capacity)
- Returns:
reference to created list
-
forward_list &operator=(forward_list &&rhs) noexcept
move assignment, list is cleared and initialized, elements are moved from source list any existing elements in ‘this’/lhs are removed (same behaviour as std::list : Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.)
- Parameters:
rhs – [in] is the list to move from (‘source’, same capacity)
- Returns:
reference to created list
-
iterator before_begin() noexcept
retrieve an interator before first element only allowed for usage in erase_after, insert_after, emplace_after Terminated when content is attemted to read (operator*, operator->)
- Returns:
iterator to fictional element before first data element
-
const_iterator before_begin() const noexcept
retrieve a const_iterator before first element only allowed for usage in erase_after, insert_after, emplace_after
- Returns:
iterator to fictional element before first data element
-
const_iterator cbefore_begin() const noexcept
const_iterator an interator before first element only allowed for usage in erase_after, insert_after, emplace_after
- Returns:
iterator to fictional element before first data element
-
iterator begin() noexcept
default list operation to retrieve an interator to first list element
- Returns:
iterator to first list element, returns iterator to end() when list is empty
-
const_iterator begin() const noexcept
default list operation to retrieve an const_iterator to first list element
- Returns:
iterator to first list element, returns iterator to end() when list is empty
-
const_iterator cbegin() const noexcept
default list operation to retrieve an const_iterator to first list element
- Returns:
iterator to first list element, returns iterator to end() when list is empty
-
iterator end() noexcept
default list operation to retrieve an interator to end of list (behind last valid element) Terminated when content is attemted to read (operator*, operator->)
- Returns:
iterator to end element, does not contain data.
-
const_iterator end() const noexcept
default list operation to retrieve an const_iterator to end of list (behind last valid element) Terminated when content is attemted to read (operator*, operator->)
- Returns:
iterator to end element, does not contain data.
-
const_iterator cend() const noexcept
default list operation to retrieve an const_iterator to end of list (behind last valid element) Terminated when content is attemted to read (operator*, operator->)
- Returns:
iterator to end element, does not contain data.
-
bool empty() const noexcept
list meta information on filling
- Returns:
no elements in list (true), otherwise (false)
-
bool full() const noexcept
list meta information on filling
- Returns:
whether list is full (filled with ‘capacity’ / ‘max_size’ elements) (true), otherwise (false)
-
size_type size() const noexcept
list meta information on filling
- Returns:
current number of elements in list @min returns min 0 @max returns max capacity
-
size_type capacity() const noexcept
list meta information, maximum number of elements the list can contain
- Returns:
list has been initialized with the following number of elements.
-
size_type max_size() const noexcept
list meta information, maximum number of elements the list can contain
- Returns:
list has been initialized with the following number of elements, same as capacity()
-
T &front() noexcept
Returns a reference to the first element in the container. calling front() on an empty list will terminate() the processing.
- Returns:
reference to the first element
-
const T &front() const noexcept
Returns a reference to the first element in the container. calling front() on an empty list will terminate() the processing.
- Returns:
const reference to the first element
-
bool push_front(const T &data) noexcept
add element to the beginning of the list
- Parameters:
data – [in] reference to data element
- Returns:
successful insertion (true), otherwise no element could be added to list (e.g. full -> false)
-
bool push_front(T &&data) noexcept
add element to the beginning of the list via move
- Parameters:
data – [in] universal reference perfectly forwarded to client class
- Returns:
successful insertion (true), otherwise no element could be added to list (e.g. full -> false)
-
bool pop_front() noexcept
remove the first element from the begining of the list element destructor will be invoked
- Returns:
successful removal (true), otherwise no element could be taken from list (e.g. empty -> false)
-
void clear() noexcept
remove all elements from the list, list will be empty element destructors will be invoked
-
iterator erase_after(const_iterator beforeToBeErasedIter) noexcept
remove next element from linked iterator position element destructors will be invoked recursive calls to erase_after only delete each 2nd element
- Parameters:
beforeToBeErasedIter – [in] iterator linking the element before the to-be-removed element
- Returns:
an (non-const_) iterator to the element after the removed element, returns end() element when reached end of list
-
size_type remove(const T &data) noexcept
remove all elements which matches the given comparing element (compare by value) requires a the template type T to have operator== defined.
- Parameters:
data – [in] value to compare to
- Returns:
the number of elements removed, return is C++20-conform
-
template<typename UnaryPredicate>
size_type remove_if(UnaryPredicate pred) noexcept remove all elements which matches the provided comparison function requires a the template type T to have a operator== defined.
- Parameters:
pred – [in] unary predicate which returns true if the element should be removed
- Returns:
the number of elements removed, return is C++20-conform
-
template<typename ...ConstructorArgs>
T &emplace_front(ConstructorArgs&&... args) noexcept construct element inplace at begining of list
- Parameters:
args – [in] T-typed construction parameters (initializer list)
- Returns:
referene to generated element, return is C++17-conform
-
template<typename ...ConstructorArgs>
iterator emplace_after(const_iterator afterToBeEmplacedIter, ConstructorArgs&&... args) noexcept construct element inplace after the pointed-to element
- Parameters:
args – [in] T-typed construction parameters (initializer list)
afterToBeEmplacedIter – [in] position in list to (construct)insert after
- Returns:
iterator to the newly added element
-
iterator insert_after(const_iterator citer, const T &data) noexcept
insert element after iterator position
- Parameters:
citer – [in] iterator with the position to insert after
data – [in] reference to element to add
- Returns:
iterator to the newly added element
-
iterator insert_after(const_iterator citer, T &&data) noexcept
add element after the pointed-to element via move
- Parameters:
citer – [in] iterator with the position to insert after
data – [in] universal reference perfectly forwarded to client class
- Returns:
iterator to the newly added element