libbmb
Modern implementation of STL
Loading...
Searching...
No Matches
bmb::LinkedList< T, TrackSize, TrackLast, Allocator > Class Template Reference

Singly linked list. More...

#include <linked_list.h>

Public Types

using value_type = T
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using size_type = size_t
 
using allocator_type = Allocator
 
using iterator = detail::LListIter< T, false >
 
using const_iterator = detail::LListIter< T, true >
 

Public Member Functions

 LinkedList () noexcept(noexcept(Allocator()))
 
 LinkedList (const Allocator &alloc)
 
 LinkedList (size_t count, const value_type &value=value_type(), const Allocator &alloc=Allocator())
 Constructs count elements with given value.
 
template<InputIterator Iter>
 LinkedList (Iter first, Iter last, const Allocator &alloc=Allocator())
 Initialize list with the given range.
 
 LinkedList (std::initializer_list< value_type > init_list, const Allocator &alloc=Allocator())
 Initialize list with the given initializer_list.
 
 LinkedList (const LinkedList &other)
 Copy constructor.
 
 LinkedList (LinkedList &&other) noexcept(noexcept(Allocator(move(other.alloc_))))
 Move constructor. No iterators are invalidated.
 
LinkedListoperator= (LinkedList other)
 Copy/move assignment operator.
 
 ~LinkedList ()
 
void swap (LinkedList &other)
 Effectively swaps content of the lists.
 
void clear () noexcept
 Removes all elements in the list.
 
iterator insertAfter (const_iterator pos, value_type value)
 Creates element and places it after the given iterator.
 
iterator insertAfter (const_iterator pos, std::initializer_list< T > init_list)
 Inserts elements from initializer list in the list.
 
template<InputIterator Iter>
iterator insertAfter (const_iterator pos, Iter first, Iter last)
 Inserts elements from [first, last) in the list after pos.
 
template<typename... Args>
iterator emplaceAfter (const_iterator pos, Args &&... args)
 Creates new node from given arguments and places it after the given position.
 
template<typename... Args>
reference emplaceFront (Args &&... args)
 Creates new node from given arguments in the start of the list.
 
template<typename... Args>
reference emplaceBack (Args &&... args)
 Creates new node from given arguments in the end of the list.
 
iterator eraseAfter (const_iterator pos) noexcept
 Destroys element right after pos.
 
iterator eraseAfter (const_iterator first, const_iterator last) noexcept
 Destroys elements in (first, last).
 
void popFront () noexcept
 Destroys first element in the list.
 
void popBack () noexcept
 Destroys last element in the list.
 
template<typename Cmp = less>
void merge (LinkedList &other, Cmp cmp=Cmp())
 See merge(LinkedList&&, auto)
 
template<typename Cmp = less>
void merge (LinkedList &&other, Cmp cmp=Cmp())
 Merges elements from 2 sorted lists into one sorted.
 
iterator spliceAfter (const_iterator pos, LinkedList &other)
 See spliceAfter(const_iterator, LinkedList&&)
 
iterator spliceAfter (const_iterator pos, LinkedList &&other)
 Transfers all elements from other to *this. other becomes empty.
 
iterator spliceAfter (const_iterator pos, LinkedList &other, const_iterator first, const_iterator last)
 See spliceAfter(const_iterator, LinkedList&&, const_iterator, const_iterator)
 
iterator spliceAfter (const_iterator pos, LinkedList &&other, const_iterator first, const_iterator last)
 Transfers all elements in (first, last) from other to *this right after pos.
 
void reverse () noexcept
 Reverses linked list.
 
reference front () noexcept
 Returns first element in the list.
 
const_reference front () const noexcept
 Returns first element in the list.
 
reference back () noexcept
 Returns last element in the list.
 
const_reference back () const noexcept
 Returns last element in the list.
 
NodegetRawFirstNode () const noexcept
 Returns raw representation of the first list's node.
 
size_t size () const noexcept
 Returns list's size.
 
bool isEmpty () const noexcept
 Checks whether list has elements.
 
allocator_type getAllocator () const
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
iterator beforeBegin () noexcept
 
const_iterator beforeBegin () const noexcept
 
const_iterator cbeforeBegin () const noexcept
 
iterator beforeEnd () noexcept
 
const_iterator beforeEnd () const noexcept
 
const_iterator cbeforeEnd () const noexcept
 
bool operator== (const LinkedList &other) const noexcept
 
auto operator<=> (const LinkedList &other) const noexcept
 

Detailed Description

template<typename T, bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
class bmb::LinkedList< T, TrackSize, TrackLast, Allocator >

Singly linked list.

Template Parameters
Ttype to hold
TrackSizeenables fast size access
TrackLastenables fast last element access
Allocatorallocator to use for memory management

This implementation may be used in several modes: 1) Memory saving: sizeof this class equals 1 pointer, but methods that use size and last element will work slowly(linearly). 2) Fast size: sizeof this class equals sizeof(void*) + sizeof(size_t), enables access to size for a constant time, 3) Fast last element: sizeof this class equals 2*sizeof(void*), last element access is constant. 4) Fast size and last element: modes 2 + 3

All methods provides strong/basics exception safety(all strong except the move assignment)

Member Typedef Documentation

◆ allocator_type

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::allocator_type = Allocator

◆ const_iterator

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::const_iterator = detail::LListIter<T, true>

◆ const_pointer

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::const_pointer = const value_type*

◆ const_reference

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::const_reference = const value_type&

◆ iterator

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::iterator = detail::LListIter<T, false>

◆ pointer

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::pointer = value_type*

◆ reference

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::reference = value_type&

◆ size_type

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::size_type = size_t

◆ value_type

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
using bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::value_type = T

Constructor & Destructor Documentation

◆ LinkedList() [1/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( )
inlinenoexcept

◆ LinkedList() [2/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( const Allocator alloc)
inlineexplicit

◆ LinkedList() [3/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( size_t  count,
const value_type value = value_type(),
const Allocator alloc = Allocator() 
)
inlineexplicit

Constructs count elements with given value.

Allocates and copy-constructs count elements one by one. Actually copies, then moves each element. So, count copies and moves are performed.

Parameters
countNumber of elements to construct
valueValue to initilize elements
allocContainer's allocator
Exceptions
Providesstrong exception guarantee.

◆ LinkedList() [4/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<InputIterator Iter>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( Iter  first,
Iter  last,
const Allocator alloc = Allocator() 
)
inline

Initialize list with the given range.

Copies all elements in [first, last). Actually copies, then moves each element.

Parameters
firstStart of the range
lastEnd of the range
allocContainer's allocator
Exceptions
Providesstrong exception guarantee.

◆ LinkedList() [5/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( std::initializer_list< value_type init_list,
const Allocator alloc = Allocator() 
)
inline

Initialize list with the given initializer_list.

Parameters
init_listInitializer list to copy
allocContainer's allocator
Exceptions
Providesstrong exception guarantee.

◆ LinkedList() [6/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( const LinkedList< T, TrackSize, TrackLast, Allocator > &  other)
inline

Copy constructor.

Exceptions
Providesstrong exception guarantee

◆ LinkedList() [7/7]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::LinkedList ( LinkedList< T, TrackSize, TrackLast, Allocator > &&  other)
inlinenoexcept

Move constructor. No iterators are invalidated.

◆ ~LinkedList()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::~LinkedList ( )
inline

Member Function Documentation

◆ back() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::back ( ) const
inlinenoexcept

Returns last element in the list.

Time complexity: 1) If TrackLast=true: O(1). 2) If TrackLast=false: O(n) where n=size().

If list is empty, UB.

◆ back() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::back ( )
inlinenoexcept

Returns last element in the list.

Time complexity: 1) If TrackLast=true: O(1). 2) If TrackLast=false: O(n) where n=size().

If list is empty, UB.

◆ beforeBegin() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::beforeBegin ( ) const
inlinenoexcept

◆ beforeBegin() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::beforeBegin ( )
inlinenoexcept

◆ beforeEnd() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::beforeEnd ( ) const
inlinenoexcept

◆ beforeEnd() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::beforeEnd ( )
inlinenoexcept

◆ begin() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::begin ( )
inlinenoexcept

◆ cbeforeBegin()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::cbeforeBegin ( ) const
inlinenoexcept

◆ cbeforeEnd()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::cbeforeEnd ( ) const
inlinenoexcept

◆ cbegin()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::cend ( ) const
inlinenoexcept

◆ clear()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::clear ( )
inlinenoexcept

Removes all elements in the list.

After this operation, there are no elements in the list, size()=0, beforeBegin()=beforeEnd().

All iterators are invalidated.

Time complexity: O(n) where n=size().

Exceptions
noexcept

◆ emplaceAfter()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<typename... Args>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::emplaceAfter ( const_iterator  pos,
Args &&...  args 
)
inline

Creates new node from given arguments and places it after the given position.

After this operation, next(pos) will give an iterator to the newly created node.

pos must be valid iterator in [beforeBegin(), end()). Otherwise UB.

No iterators are invalidated.

Time complexity: O(1).

Parameters
posPosition to insert after
args...Arguments to forward in the element's c-tor
Returns
iterator to the created element
Exceptions
Providesstrong exception guarantee

◆ emplaceBack()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<typename... Args>
reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::emplaceBack ( Args &&...  args)
inline

Creates new node from given arguments in the end of the list.

That's it, places the new node after prev(end()), so it becomes last element in the list.

See emplaceAfter(const_iterator, Args&&...) docs for details.

Time complexity: 1) If TrackLast=true: O(1). 2) If TrackLast=false: O(n) where n=size().

Parameters
args...Arguments to forward in the element's c-tor
Returns
iterator to the created element
Exceptions
Providesstrong exception guarantee

◆ emplaceFront()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<typename... Args>
reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::emplaceFront ( Args &&...  args)
inline

Creates new node from given arguments in the start of the list.

That's it, places the new node after beforeBegin(), so it becomes begin().

See emplaceAfter(const_iterator, Args&&...) docs for details.

Time complexity: O(1).

Parameters
args...Arguments to forward in the element's c-tor
Returns
iterator to the created element
Exceptions
Providesstrong exception guarantee

◆ end() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::end ( )
inlinenoexcept

◆ eraseAfter() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::eraseAfter ( const_iterator  first,
const_iterator  last 
)
inlinenoexcept

Destroys elements in (first, last).

That's it, all elements from next(first) to prev(last) are erased. And next(first) becomes equal to last.

first and last must be valid iterators in [beforeBegin(), end()]. Otherwise UB.

No iterators, except ones to the erased elements, are invalidated.

If first==last or next(first)==last, does nothing.

Parameters
firstIterator to start the erase after
lastIterator to end the erase before
Returns
last
Exceptions
noexcept

◆ eraseAfter() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::eraseAfter ( const_iterator  pos)
inlinenoexcept

Destroys element right after pos.

pos must be valid iterator in [cbeforeBegin(), end). If pos is the last element in the list or isEmpty()==true, does nothing.

No iterators, except one to the erased element, are invalidated.

Parameters
posIterator to destroy after
Returns
iterator to the element after destroyed one
Exceptions
noexcept

◆ front() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
const_reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::front ( ) const
inlinenoexcept

Returns first element in the list.

If list is empty, UB.

◆ front() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
reference bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::front ( )
inlinenoexcept

Returns first element in the list.

If list is empty, UB.

◆ getAllocator()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
allocator_type bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::getAllocator ( ) const
inline

◆ getRawFirstNode()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
Node * bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::getRawFirstNode ( ) const
inlinenoexcept

Returns raw representation of the first list's node.

Generally, you should not use it.

◆ insertAfter() [1/3]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<InputIterator Iter>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::insertAfter ( const_iterator  pos,
Iter  first,
Iter  last 
)
inline

Inserts elements from [first, last) in the list after pos.

That's it, copies elements in [first, last) and places them between pos and next(pos).

pos must be valid iterator in [beforeBegin(), end()). Otherwise UB.

No iterators are invalidated.

Time complexity: O(distance(first, last)) - number elements to insert.

Parameters
posIterator to place range after
firstStart of range
lastEnd of range
Returns
iterator to the last element inserted, or pos if first==last
Exceptions
Providesstrong exception guarantee.

◆ insertAfter() [2/3]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::insertAfter ( const_iterator  pos,
std::initializer_list< T init_list 
)
inline

Inserts elements from initializer list in the list.

Actually calls insertAfter(pos, init_list.begin(), init_list.end()). See its docs for details.

Time complexity: O(n) where n=number elements to insert.

Parameters
posIterator to place elements after
init_listInitializer list to copy
Returns
iterator to the last element inserted, or pos if init_list is empty.
Exceptions
Providesstrong exception guarantee.

◆ insertAfter() [3/3]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::insertAfter ( const_iterator  pos,
value_type  value 
)
inline

Creates element and places it after the given iterator.

Actually calls emplaceAfter(pos, bmb::move(value)). See its docs for details.

Parameters
posPosition to insert after
valueValue to initialize new node

Time complexity: O(1).

Returns
iterator to the created element
Exceptions
Providesstrong exception guarantee

◆ isEmpty()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bool bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::isEmpty ( ) const
inlinenoexcept

Checks whether list has elements.

Returns
true, if list is empty. Otherwise false.
Exceptions
noexcept

◆ merge() [1/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<typename Cmp = less>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::merge ( LinkedList< T, TrackSize, TrackLast, Allocator > &&  other,
Cmp  cmp = Cmp() 
)
inline

Merges elements from 2 sorted lists into one sorted.

Transfers all elements from other to this, so this is sorted. other becomes empty after this operation.

Assumes that this and other are already sorted according to cmp. If they don't, resulting list will be unpredictably merged. Current implementation is NOT stable.

this->getAllocator() must be equal to other.getAllocator(). Otherwise exception is thrown.

If other refers to this, does nothing.

No iterators are invalidated.

Time complexity: O(max(this->size(), other.size())).

Parameters
otherList to merge with
cmpComparator to use
Exceptions
Providesconditional exception safety. If allocators are different - throws std::runtime_error. If a call to cmp throws - no exception guarantee, there will be memory leak. Otherwise noexcept.

◆ merge() [2/2]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
template<typename Cmp = less>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::merge ( LinkedList< T, TrackSize, TrackLast, Allocator > &  other,
Cmp  cmp = Cmp() 
)
inline

See merge(LinkedList&&, auto)

◆ operator<=>()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
auto bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::operator<=> ( const LinkedList< T, TrackSize, TrackLast, Allocator > &  other) const
inlinenoexcept

◆ operator=()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
LinkedList & bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::operator= ( LinkedList< T, TrackSize, TrackLast, Allocator other)
inline

Copy/move assignment operator.

No iterators are invalidated.

Exceptions
Providesconditional exception safety. If operator is used as a copy operator, strong guarantee. If operator is used as a move operator and interanal call to swap throws(due to allocator), basic guarantee, since moved value will be destroyed.

◆ operator==()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
bool bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::operator== ( const LinkedList< T, TrackSize, TrackLast, Allocator > &  other) const
inlinenoexcept

◆ popBack()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::popBack ( )
inlinenoexcept

Destroys last element in the list.

If isEmpty()==true, does nothing.

Finds element before the last in the list and calls eraseAfter on it. By construction, to find node before the last one we need to iterate over the whole list.

No iterators, except one to the erased element, are invalidated.

Time complexity: O(n) where n=size().

Exceptions
noexcept

◆ popFront()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::popFront ( )
inlinenoexcept

Destroys first element in the list.

Actually calls eraseAfter(cbeforeBegin()). See its docs for details.

Exceptions
noexcept

◆ reverse()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::reverse ( )
inlinenoexcept

Reverses linked list.

Time complexity: O(n) where n=size()

No iterators, except one to the erased element, are invalidated.

Exceptions
noexcept

◆ size()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
size_t bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::size ( ) const
inlinenoexcept

Returns list's size.

Time complexity: 1) If TrackSize=true: O(1). 2) If TrackSize=false: O(n) where n - num. of elements in list.

Returns
number of elements in the list
Exceptions
noexcept

◆ spliceAfter() [1/4]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::spliceAfter ( const_iterator  pos,
LinkedList< T, TrackSize, TrackLast, Allocator > &&  other 
)
inline

Transfers all elements from other to *this. other becomes empty.

this->getAllocator() must be equal to other.getAllocator(). Otherwise exception is thrown.

pos must be valid iterator in [beforeBegin(), end()). Otherwise UB.

If other refers to *this, does nothing.

No iterators are invalidated.

Time complexity: 1) If TrackLast==true: O(1). 2) If TrackLast==false: O(other.size()).

Parameters
posIterator to transfer after
otherList to transfer from
Returns
iterator to the last element transferred or pos
Exceptions
std::runtime_errorif allocators aren't equal

◆ spliceAfter() [2/4]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::spliceAfter ( const_iterator  pos,
LinkedList< T, TrackSize, TrackLast, Allocator > &&  other,
const_iterator  first,
const_iterator  last 
)
inline

Transfers all elements in (first, last) from other to *this right after pos.

If first==last or next(first)==last, does nothing and returns pos.

other can refer to *this. In this case pos must not be in (first, last), otherwise UB - at least memory leak.

this->getAllocator() must be equal to other.getAllocator(). Otherwise exception is thrown.

pos must be valid iterator in [beforeBegin(), end()). Otherwise UB.

No iterators are invalidated.

Time complexity: O(distance(first, last)).

Parameters
posIterator to transfer range after
otherList to transfer from
firstIterator before the element to start cut
lastIterator after the element to stop cut
Returns
iterator to the last element transferred or pos
Exceptions
std::runtime_errorif allocators aren't equal

◆ spliceAfter() [3/4]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::spliceAfter ( const_iterator  pos,
LinkedList< T, TrackSize, TrackLast, Allocator > &  other 
)
inline

See spliceAfter(const_iterator, LinkedList&&)

◆ spliceAfter() [4/4]

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
iterator bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::spliceAfter ( const_iterator  pos,
LinkedList< T, TrackSize, TrackLast, Allocator > &  other,
const_iterator  first,
const_iterator  last 
)
inline

See spliceAfter(const_iterator, LinkedList&&, const_iterator, const_iterator)

◆ swap()

template<typename T , bool TrackSize = true, bool TrackLast = true, typename Allocator = PrimitiveAllocator>
void bmb::LinkedList< T, TrackSize, TrackLast, Allocator >::swap ( LinkedList< T, TrackSize, TrackLast, Allocator > &  other)
inline

Effectively swaps content of the lists.

No iterators are invalidated.

Parameters
otherLists to swap with
Exceptions
Sameas swap for allocators

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