fiber
Loading...
Searching...
No Matches
fiber::ArrayList< T, N > Class Template Reference

An array of contiguous memory which is statically allocated. More...

#include <ArrayList.hpp>

Public Types

using value_type = T
 
using size_type = std::size_t
 
using reference = T&
 
using const_reference = const T&
 
using iterator = T*
 
using const_iterator = const T*
 
using pointer = T*
 
using const_pointer = T*
 

Public Member Functions

 ArrayList ()=default
 default constructor
 
template<std::convertible_to< T > Ta, size_t N1>
 ArrayList (const ArrayList< Ta, N1 > &other)
 default copy constructor
 
template<std::convertible_to< T > Ta, size_t N1>
ArrayListoperator= (const ArrayList< Ta, N1 > &other)
 default copy assignment
 
template<std::convertible_to< T > Ta>
 ArrayList (std::initializer_list< Ta > ilist)
 construct from an initialiser list
 
template<std::ranges::forward_range Range>
 ArrayList (const Range &range)
 construct from an generic range that follows the concept std::ranges::forward_range
 
 ~ArrayList ()
 destructor
 
constexpr size_type size () const
 returns the size/count of live elements in the container
 
constexpr size_type capacity () const
 returns the capacity of the container. Since this is a statically allocated container this is also the maximal size.
 
constexpr size_type max_size () const
 returns the maximal number of elements that can be stored in the container
 
constexpr size_type reserve () const
 returns the reserve - number of elements that can be stored until the container is full
 
constexpr bool empty () const
 returns true if there are not elements in the container, aka. the container is empty.
 
constexpr bool full () const
 returns true if the container is full and no more elements can be stored in the container
 
constexpr pointer data ()
 returns a pointer to the start of the container
 
constexpr const_pointer data () const
 returns a const-pointer to the start of the container
 
constexpr const_pointer cdata () const
 returns a const-pointer to the start of the container
 
constexpr iterator begin ()
 returns an iterator to the start
 
constexpr const_iterator begin () const
 returns a const-iterator to the start
 
constexpr const_iterator cbegin () const
 returns a const-iterator to the start
 
constexpr iterator end ()
 returns an iterator past the end
 
constexpr const_iterator end () const
 returns a const-iterator past the end
 
constexpr const_iterator cend () const
 returns a const-iterator past the end
 
constexpr reference front ()
 returns a reference to the first element in the buffer
 
constexpr const_reference front () const
 returns a const-reference to the first element int the buffer
 
constexpr reference back ()
 returns a reference to the last element in the buffer
 
constexpr const_reference back () const
 returns a const reference to the last element in the buffer
 
template<std::integral Int>
constexpr reference at (const Int i)
 returns a reference to the element at the given position
 
template<std::integral Int>
constexpr const_reference at (const Int i) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
ArrayList< T, N > at (const ArrayList< bool, N > &mask) const
 Masked indexing.
 
template<std::integral Int>
ArrayList< T, N > at (const ArrayList< Int, N > &indices) const
 Indices list indexing.
 
template<std::integral Int>
constexpr reference operator[] (const Int i)
 returns a reference to the element at the given position
 
template<std::integral Int>
constexpr const_reference operator[] (const Int i) const
 returns a reference to the element at the given position
 
ArrayList< T, N > operator[] (const ArrayList< bool, N > &mask) const
 accesses all elements where mask is true
 
template<std::integral Int>
ArrayList< T, N > operator[] (const ArrayList< Int, N > &indices) const
 accesses all elements at the given indices
 
template<class... Args>
T & emplace_back (Args &&... args)
 emplaces (aka. pushes) an element to the back of the list
 
void clear ()
 clears the list - destructs all members if necessary and sets the size to zero
 
void append (const size_type count, const T &value)
 appends value count many times
 
void assign (const size_type count, const T &value)
 clears the list and assigns the value count many times to the list.
 
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
void append (Itr first, Itr last)
 appends a range defined by foreward iterators using the closed-open principle [first, last)
 
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
void assign (Itr first, Itr last)
 assigns a range defined by foreward iterators using the closed-open principle [first, last). After the assignment the list has the size of the assigned range
 
template<std::convertible_to< T > Ta>
void append (std::initializer_list< Ta > ilist)
 appens an initilizer_list
 
template<std::convertible_to< T > Ta>
void assign (std::initializer_list< Ta > ilist)
 assigns an initializer_list
 
template<std::ranges::forward_range Range>
void append (const Range &range)
 Appends the content of a range.
 
template<std::ranges::forward_range Range>
void assign (const Range &range)
 Assigns the content of a range.
 
constexpr size_type to_index (const const_iterator pos) const
 turns the passed position given by an iterator into an integer
 
template<std::integral Int>
constexpr iterator to_iterator (const Int pos)
 turns the passed unsigned integer into an iterator pointing to the same position
 
template<std::integral Int>
constexpr const_iterator to_iterator (const Int pos) const
 turns the passed unsigned integer into a cosnt_iterator pointing to the same position
 
template<std::integral Int>
constexpr const_iterator to_const_iterator (const Int pos) const
 turns the passed unsigned integer into a cosnt_iterator pointing to the same position
 
constexpr iterator unconst (const const_iterator pos)
 removes the constnes of an iterator if the user has access to the mutable (un-const) container
 
template<std::convertible_to< T > Ta>
iterator insert (const const_iterator pos, const Ta &value)
 Inserts a value.
 
template<std::convertible_to< T > Ta>
iterator insert (const const_iterator pos, Ta &&value)
 Inserts a value.
 
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
iterator insert (const const_iterator pos, Itr first, Itr last)
 inserts a range at a given position
 
template<std::ranges::forward_range Range>
iterator insert (const const_iterator pos, const Range &range)
 inserts a range at the given position
 
template<std::integral Int>
iterator insert (const Int index, const T &value)
 inserts the value at the position passed as an integer that wraps if it is a signed type
 
template<std::integral Int, std::convertible_to< T > Ta>
iterator insert (const Int index, Ta &&value)
 inserts the value at the position passed as an integer that wraps if it is a signed type
 
template<std::integral Int, std::ranges::forward_range Range>
iterator insert (const Int index, const Range &range)
 inserts the range at the position passed as an integer that wraps if it is a signed type
 
template<std::integral Int, std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
iterator insert (const Int index, Itr first, Itr last)
 inserts the closed-open [first, last) range at the given position
 
iterator erase (const_iterator cpos)
 erases/removes the element at the position pointed to by cpos
 
template<class Int>
requires std::is_integral_v<Int>
iterator erase (const Int pos)
 erases/removes the element at the position pointed to by cpos
 
iterator erase (const_iterator first, const_iterator last)
 erases/removes the range given by the closed-open iterators [first, last)
 
template<class Callable>
std::size_t erase_if (Callable &&f)
 erases elements from the list if they satisfy the callable
 
template<class Int>
requires std::is_integral_v<Int>
iterator erase (Int first, Int last)
 erases/removes the range given by the closed-open indices [first, last)
 
void pop_back ()
 removes and destructs the last element
 
ArrayList< bool, N > operator! () const
 Applies the negation (!) operator to all elements and returns it as a bool list.
 
template<class Function>
constexpr void for_each (Function &&function)
 Applies the function to each element of the list in-place.
 

Detailed Description

template<class T, std::size_t N>
class fiber::ArrayList< T, N >

An array of contiguous memory which is statically allocated.

Failure Modes and Effects Analysis

Template Parameters
Ttype of the data elements
Nsize/count of the elements in the container

Member Typedef Documentation

◆ const_iterator

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::const_iterator = const T*

◆ const_pointer

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::const_pointer = T*

◆ const_reference

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::const_reference = const T&

◆ iterator

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::iterator = T*

◆ pointer

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::pointer = T*

◆ reference

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::reference = T&

◆ size_type

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::size_type = std::size_t

◆ value_type

template<class T, std::size_t N>
using fiber::ArrayList< T, N >::value_type = T

Constructor & Destructor Documentation

◆ ArrayList() [1/4]

template<class T, std::size_t N>
fiber::ArrayList< T, N >::ArrayList ( )
default

default constructor

◆ ArrayList() [2/4]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta, size_t N1>
fiber::ArrayList< T, N >::ArrayList ( const ArrayList< Ta, N1 > & other)
inline

default copy constructor

◆ ArrayList() [3/4]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta>
fiber::ArrayList< T, N >::ArrayList ( std::initializer_list< Ta > ilist)
inline

construct from an initialiser list

Parameters
ilistinitialiser list

◆ ArrayList() [4/4]

template<class T, std::size_t N>
template<std::ranges::forward_range Range>
fiber::ArrayList< T, N >::ArrayList ( const Range & range)
inline

construct from an generic range that follows the concept std::ranges::forward_range

Template Parameters
Rangetemplated range class that follows the concept std::ranges::forward_range
Parameters
rangethe range that should be assigned on construction

◆ ~ArrayList()

template<class T, std::size_t N>
fiber::ArrayList< T, N >::~ArrayList ( )
inline

destructor

Member Function Documentation

◆ append() [1/4]

template<class T, std::size_t N>
template<std::ranges::forward_range Range>
void fiber::ArrayList< T, N >::append ( const Range & range)
inline

Appends the content of a range.

◆ append() [2/4]

template<class T, std::size_t N>
void fiber::ArrayList< T, N >::append ( const size_type count,
const T & value )
inline

appends value count many times

Parameters
counthow often value should be emplaced_back()
valuethe value to be created

◆ append() [3/4]

template<class T, std::size_t N>
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
void fiber::ArrayList< T, N >::append ( Itr first,
Itr last )
inline

appends a range defined by foreward iterators using the closed-open principle [first, last)

◆ append() [4/4]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta>
void fiber::ArrayList< T, N >::append ( std::initializer_list< Ta > ilist)
inline

appens an initilizer_list

◆ assign() [1/4]

template<class T, std::size_t N>
template<std::ranges::forward_range Range>
void fiber::ArrayList< T, N >::assign ( const Range & range)
inline

Assigns the content of a range.

◆ assign() [2/4]

template<class T, std::size_t N>
void fiber::ArrayList< T, N >::assign ( const size_type count,
const T & value )
inline

clears the list and assigns the value count many times to the list.

◆ assign() [3/4]

template<class T, std::size_t N>
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
void fiber::ArrayList< T, N >::assign ( Itr first,
Itr last )
inline

assigns a range defined by foreward iterators using the closed-open principle [first, last). After the assignment the list has the size of the assigned range

◆ assign() [4/4]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta>
void fiber::ArrayList< T, N >::assign ( std::initializer_list< Ta > ilist)
inline

assigns an initializer_list

◆ at() [1/4]

template<class T, std::size_t N>
ArrayList< T, N > fiber::ArrayList< T, N >::at ( const ArrayList< bool, N > & mask) const
inline

Masked indexing.

Parameters
maskthe mask that selects which elements to get. true will be included, false excluded
Returns
A ArrayList that contains all values where of this where mask is true

◆ at() [2/4]

template<class T, std::size_t N>
template<std::integral Int>
ArrayList< T, N > fiber::ArrayList< T, N >::at ( const ArrayList< Int, N > & indices) const
inline

Indices list indexing.

Template Parameters
Inta generic integer
Parameters
indicesa list of indices that should be extracted
Returns
a ArrayList containing all the elements from this that are contained in the indices

◆ at() [3/4]

template<class T, std::size_t N>
template<std::integral Int>
reference fiber::ArrayList< T, N >::at ( const Int i)
inlineconstexpr

returns a reference to the element at the given position

For signed integer types, signed ones will wrap negatives around so -1 will access the last element Unsigned integer types will avoid the branch.

◆ at() [4/4]

template<class T, std::size_t N>
template<std::integral Int>
const_reference fiber::ArrayList< T, N >::at ( const Int i) const
inlineconstexpr

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

◆ back() [1/2]

template<class T, std::size_t N>
reference fiber::ArrayList< T, N >::back ( )
inlineconstexpr

returns a reference to the last element in the buffer

◆ back() [2/2]

template<class T, std::size_t N>
const_reference fiber::ArrayList< T, N >::back ( ) const
inlineconstexpr

returns a const reference to the last element in the buffer

◆ begin() [1/2]

template<class T, std::size_t N>
iterator fiber::ArrayList< T, N >::begin ( )
inlineconstexpr

returns an iterator to the start

◆ begin() [2/2]

template<class T, std::size_t N>
const_iterator fiber::ArrayList< T, N >::begin ( ) const
inlineconstexpr

returns a const-iterator to the start

◆ capacity()

template<class T, std::size_t N>
size_type fiber::ArrayList< T, N >::capacity ( ) const
inlineconstexpr

returns the capacity of the container. Since this is a statically allocated container this is also the maximal size.

◆ cbegin()

template<class T, std::size_t N>
const_iterator fiber::ArrayList< T, N >::cbegin ( ) const
inlineconstexpr

returns a const-iterator to the start

◆ cdata()

template<class T, std::size_t N>
const_pointer fiber::ArrayList< T, N >::cdata ( ) const
inlineconstexpr

returns a const-pointer to the start of the container

◆ cend()

template<class T, std::size_t N>
const_iterator fiber::ArrayList< T, N >::cend ( ) const
inlineconstexpr

returns a const-iterator past the end

◆ clear()

template<class T, std::size_t N>
void fiber::ArrayList< T, N >::clear ( )
inline

clears the list - destructs all members if necessary and sets the size to zero

◆ data() [1/2]

template<class T, std::size_t N>
pointer fiber::ArrayList< T, N >::data ( )
inlineconstexpr

returns a pointer to the start of the container

◆ data() [2/2]

template<class T, std::size_t N>
const_pointer fiber::ArrayList< T, N >::data ( ) const
inlineconstexpr

returns a const-pointer to the start of the container

◆ emplace_back()

template<class T, std::size_t N>
template<class... Args>
T & fiber::ArrayList< T, N >::emplace_back ( Args &&... args)
inline

emplaces (aka. pushes) an element to the back of the list

Actually constructs an element in place

Template Parameters
...Argslist of parameters that correspond to a constructor of the value type of the list
Parameters
...argslist of arguments to construct a value of the list
Returns
a reference to the constructed list element

◆ empty()

template<class T, std::size_t N>
bool fiber::ArrayList< T, N >::empty ( ) const
inlineconstexpr

returns true if there are not elements in the container, aka. the container is empty.

◆ end() [1/2]

template<class T, std::size_t N>
iterator fiber::ArrayList< T, N >::end ( )
inlineconstexpr

returns an iterator past the end

◆ end() [2/2]

template<class T, std::size_t N>
const_iterator fiber::ArrayList< T, N >::end ( ) const
inlineconstexpr

returns a const-iterator past the end

◆ erase() [1/4]

template<class T, std::size_t N>
template<class Int>
requires std::is_integral_v<Int>
iterator fiber::ArrayList< T, N >::erase ( const Int pos)
inline

erases/removes the element at the position pointed to by cpos

does not perform out of bounds checks

Returns
an iterator the element after the removed one

◆ erase() [2/4]

template<class T, std::size_t N>
iterator fiber::ArrayList< T, N >::erase ( const_iterator cpos)
inline

erases/removes the element at the position pointed to by cpos

does not perform out of bounds checks

Returns
an iterator the element after the removed one

◆ erase() [3/4]

template<class T, std::size_t N>
iterator fiber::ArrayList< T, N >::erase ( const_iterator first,
const_iterator last )
inline

erases/removes the range given by the closed-open iterators [first, last)

does not perform out of bounds checks

Returns
an iterator the element after the removed ones

◆ erase() [4/4]

template<class T, std::size_t N>
template<class Int>
requires std::is_integral_v<Int>
iterator fiber::ArrayList< T, N >::erase ( Int first,
Int last )
inline

erases/removes the range given by the closed-open indices [first, last)

does not perform out of bounds checks

Returns
an iterator the element after the removed ones

◆ erase_if()

template<class T, std::size_t N>
template<class Callable>
std::size_t fiber::ArrayList< T, N >::erase_if ( Callable && f)
inline

erases elements from the list if they satisfy the callable

Template Parameters
CallableObject that can be called like bool f(const T&) or bool f(T).
Parameters
fCondition that returns true if that element should be erased from the list.

◆ for_each()

template<class T, std::size_t N>
template<class Function>
void fiber::ArrayList< T, N >::for_each ( Function && function)
inlineconstexpr

Applies the function to each element of the list in-place.

Note
This is an in-place operation and will change the list. If you want to create a new list with the transformed values, use fiber::for_each(const ArrayList<T, N>&, std::function<T, const T&> function) instead
Parameters
functionthe function being applied to change/transform each element

◆ front() [1/2]

template<class T, std::size_t N>
reference fiber::ArrayList< T, N >::front ( )
inlineconstexpr

returns a reference to the first element in the buffer

◆ front() [2/2]

template<class T, std::size_t N>
const_reference fiber::ArrayList< T, N >::front ( ) const
inlineconstexpr

returns a const-reference to the first element int the buffer

◆ full()

template<class T, std::size_t N>
bool fiber::ArrayList< T, N >::full ( ) const
inlineconstexpr

returns true if the container is full and no more elements can be stored in the container

◆ insert() [1/8]

template<class T, std::size_t N>
template<std::ranges::forward_range Range>
iterator fiber::ArrayList< T, N >::insert ( const const_iterator pos,
const Range & range )
inline

inserts a range at the given position

Template Parameters
Rangea generic range that follows the concept std::ranges::forward_range
Parameters
posthe insertion point
rangethe range that should be inserted
Returns
an iterator to the inserted range

◆ insert() [2/8]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta>
iterator fiber::ArrayList< T, N >::insert ( const const_iterator pos,
const Ta & value )
inline

Inserts a value.

Template Parameters
TaA type that is convertible to the value_type of the list
Parameters
posthe position at which the value should be inserted
valuethe value that the element at that position should have after the insertion
Returns
an iterator pointing to the inserted value

◆ insert() [3/8]

template<class T, std::size_t N>
template<std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
iterator fiber::ArrayList< T, N >::insert ( const const_iterator pos,
Itr first,
Itr last )
inline

inserts a range at a given position

Template Parameters
Itra generic iterator that follows the concept std::forward_iterator
Parameters
posthe position at which should be inserted given by an iterator
firstthe start of the range that should be inserted
lastthe past the end iterator to which should be inserted
Returns
an iterator to the start of the start of the insertion

◆ insert() [4/8]

template<class T, std::size_t N>
template<std::convertible_to< T > Ta>
iterator fiber::ArrayList< T, N >::insert ( const const_iterator pos,
Ta && value )
inline

Inserts a value.

Parameters
posthe position at which the value should be inserted
valuethe value that the element at that position should have after the insertion
Returns
an iterator pointing to the inserted value

◆ insert() [5/8]

template<class T, std::size_t N>
template<std::integral Int, std::ranges::forward_range Range>
iterator fiber::ArrayList< T, N >::insert ( const Int index,
const Range & range )
inline

inserts the range at the position passed as an integer that wraps if it is a signed type

◆ insert() [6/8]

template<class T, std::size_t N>
template<std::integral Int>
iterator fiber::ArrayList< T, N >::insert ( const Int index,
const T & value )
inline

inserts the value at the position passed as an integer that wraps if it is a signed type

◆ insert() [7/8]

template<class T, std::size_t N>
template<std::integral Int, std::forward_iterator Itr>
requires std::convertible_to<typename std::iterator_traits<Itr>::value_type, T>
iterator fiber::ArrayList< T, N >::insert ( const Int index,
Itr first,
Itr last )
inline

inserts the closed-open [first, last) range at the given position

◆ insert() [8/8]

template<class T, std::size_t N>
template<std::integral Int, std::convertible_to< T > Ta>
iterator fiber::ArrayList< T, N >::insert ( const Int index,
Ta && value )
inline

inserts the value at the position passed as an integer that wraps if it is a signed type

◆ max_size()

template<class T, std::size_t N>
size_type fiber::ArrayList< T, N >::max_size ( ) const
inlineconstexpr

returns the maximal number of elements that can be stored in the container

◆ operator!()

template<class T, std::size_t N>
ArrayList< bool, N > fiber::ArrayList< T, N >::operator! ( ) const
inline

Applies the negation (!) operator to all elements and returns it as a bool list.

◆ operator=()

template<class T, std::size_t N>
template<std::convertible_to< T > Ta, size_t N1>
ArrayList & fiber::ArrayList< T, N >::operator= ( const ArrayList< Ta, N1 > & other)
inline

default copy assignment

◆ operator[]() [1/4]

template<class T, std::size_t N>
ArrayList< T, N > fiber::ArrayList< T, N >::operator[] ( const ArrayList< bool, N > & mask) const
inline

accesses all elements where mask is true

◆ operator[]() [2/4]

template<class T, std::size_t N>
template<std::integral Int>
ArrayList< T, N > fiber::ArrayList< T, N >::operator[] ( const ArrayList< Int, N > & indices) const
inline

accesses all elements at the given indices

◆ operator[]() [3/4]

template<class T, std::size_t N>
template<std::integral Int>
reference fiber::ArrayList< T, N >::operator[] ( const Int i)
inlineconstexpr

returns a reference to the element at the given position

◆ operator[]() [4/4]

template<class T, std::size_t N>
template<std::integral Int>
const_reference fiber::ArrayList< T, N >::operator[] ( const Int i) const
inlineconstexpr

returns a reference to the element at the given position

◆ pop_back()

template<class T, std::size_t N>
void fiber::ArrayList< T, N >::pop_back ( )
inline

removes and destructs the last element

◆ reserve()

template<class T, std::size_t N>
size_type fiber::ArrayList< T, N >::reserve ( ) const
inlineconstexpr

returns the reserve - number of elements that can be stored until the container is full

◆ size()

template<class T, std::size_t N>
size_type fiber::ArrayList< T, N >::size ( ) const
inlineconstexpr

returns the size/count of live elements in the container

◆ to_const_iterator()

template<class T, std::size_t N>
template<std::integral Int>
const_iterator fiber::ArrayList< T, N >::to_const_iterator ( const Int pos) const
inlineconstexpr

turns the passed unsigned integer into a cosnt_iterator pointing to the same position

◆ to_index()

template<class T, std::size_t N>
size_type fiber::ArrayList< T, N >::to_index ( const const_iterator pos) const
inlineconstexpr

turns the passed position given by an iterator into an integer

◆ to_iterator() [1/2]

template<class T, std::size_t N>
template<std::integral Int>
iterator fiber::ArrayList< T, N >::to_iterator ( const Int pos)
inlineconstexpr

turns the passed unsigned integer into an iterator pointing to the same position

◆ to_iterator() [2/2]

template<class T, std::size_t N>
template<std::integral Int>
const_iterator fiber::ArrayList< T, N >::to_iterator ( const Int pos) const
inlineconstexpr

turns the passed unsigned integer into a cosnt_iterator pointing to the same position

◆ unconst()

template<class T, std::size_t N>
iterator fiber::ArrayList< T, N >::unconst ( const const_iterator pos)
inlineconstexpr

removes the constnes of an iterator if the user has access to the mutable (un-const) container


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