SPH
Public Member Functions | Friends | List of all members
List< T, TAllocator > Class Template Reference

Doubly-linked list. More...

#include <List.h>

Inheritance diagram for List< T, TAllocator >:
Noncopyable

Public Member Functions

 List ()
 Constructs the list with no elements. More...
 
 List (std::initializer_list< StorageType > list)
 Constructs the list given initializer_list of elements. More...
 
 List (List &&other)
 Move constructor. More...
 
 ~List ()
 
Listoperator= (List &&other)
 Move operator. More...
 
INLINE bool empty () const
 Returns true if there are no elements in the list. More...
 
INLINE Size size () const
 Returns the number of elements in the list. More...
 
template<typename U >
void pushBack (U &&value)
 Adds a new element to the back of the list. More...
 
template<typename U >
void pushFront (U &&value)
 Adds a new element to the beginning of the list. More...
 
template<typename U >
void insert (const ListIterator< T > iter, U &&value)
 
ListIterator< T > erase (const ListIterator< T > iter)
 Removes an element given by the iterator. More...
 
void clear ()
 Removes all elements from the list. More...
 
INLINE T & front ()
 Returns the reference to the first element in the list. More...
 
INLINE const T & front () const
 Returns the reference to the first element in the list. More...
 
INLINE T & back ()
 Returns the reference to the last element in the list. More...
 
INLINE const T & back () const
 Returns the reference to the last element in the list. More...
 
List clone () const
 Creates a copy of the list. More...
 
ListIterator< T > begin ()
 Returns a bidirectional iterator pointing to the first element of the list. More...
 
ListIterator< const T > begin () const
 Returns a bidirectional iterator pointing to the first element of the list. More...
 
ListIterator< T > end ()
 Returns a bidirectional iterator pointing to the one-past-last element of the list. More...
 
ListIterator< const T > end () const
 Returns a bidirectional iterator pointing to the one-past-last element of the list. More...
 
const TAllocator & allocator () const
 Returns the interface to the allocator. More...
 
TAllocator & allocator ()
 Returns the interface to the allocator. More...
 
- Public Member Functions inherited from Noncopyable
 Noncopyable ()=default
 
 Noncopyable (const Noncopyable &)=delete
 
 Noncopyable (Noncopyable &&)=default
 
Noncopyableoperator= (const Noncopyable &)=delete
 
Noncopyableoperator= (Noncopyable &&)=default
 

Friends

template<typename TStream >
TStream & operator<< (TStream &stream, const List &array)
 Prints content of the list to stream. Stored values must have overloaded << operator. More...
 

Detailed Description

template<typename T, typename TAllocator>
class List< T, TAllocator >

Doubly-linked list.

Random access is not implemented, as it would be highly ineffective anyway.

Definition at line 131 of file List.h.

Constructor & Destructor Documentation

◆ List() [1/3]

template<typename T , typename TAllocator >
List< T, TAllocator >::List ( )
inline

Constructs the list with no elements.

Definition at line 140 of file List.h.

◆ List() [2/3]

template<typename T , typename TAllocator >
List< T, TAllocator >::List ( std::initializer_list< StorageType >  list)
inline

Constructs the list given initializer_list of elements.

Definition at line 145 of file List.h.

◆ List() [3/3]

template<typename T , typename TAllocator >
List< T, TAllocator >::List ( List< T, TAllocator > &&  other)
inline

Move constructor.

Definition at line 152 of file List.h.

◆ ~List()

template<typename T , typename TAllocator >
List< T, TAllocator >::~List ( )
inline

Definition at line 158 of file List.h.

Member Function Documentation

◆ allocator() [1/2]

template<typename T , typename TAllocator >
TAllocator& List< T, TAllocator >::allocator ( )
inline

Returns the interface to the allocator.

Definition at line 322 of file List.h.

◆ allocator() [2/2]

template<typename T , typename TAllocator >
const TAllocator& List< T, TAllocator >::allocator ( ) const
inline

Returns the interface to the allocator.

Definition at line 317 of file List.h.

◆ back() [1/2]

template<typename T , typename TAllocator >
INLINE T& List< T, TAllocator >::back ( )
inline

Returns the reference to the last element in the list.

Definition at line 274 of file List.h.

◆ back() [2/2]

template<typename T , typename TAllocator >
INLINE const T& List< T, TAllocator >::back ( ) const
inline

Returns the reference to the last element in the list.

Definition at line 280 of file List.h.

◆ begin() [1/2]

template<typename T , typename TAllocator >
ListIterator<T> List< T, TAllocator >::begin ( )
inline

Returns a bidirectional iterator pointing to the first element of the list.

Definition at line 295 of file List.h.

◆ begin() [2/2]

template<typename T , typename TAllocator >
ListIterator<const T> List< T, TAllocator >::begin ( ) const
inline

Returns a bidirectional iterator pointing to the first element of the list.

Todo:
is this ok? better solution?

Definition at line 300 of file List.h.

◆ clear()

template<typename T , typename TAllocator >
void List< T, TAllocator >::clear ( )
inline

Removes all elements from the list.

Definition at line 250 of file List.h.

◆ clone()

template<typename T , typename TAllocator >
List List< T, TAllocator >::clone ( ) const
inline

Creates a copy of the list.

Definition at line 286 of file List.h.

◆ empty()

template<typename T , typename TAllocator >
INLINE bool List< T, TAllocator >::empty ( ) const
inline

Returns true if there are no elements in the list.

Definition at line 170 of file List.h.

◆ end() [1/2]

template<typename T , typename TAllocator >
ListIterator<T> List< T, TAllocator >::end ( )
inline

Returns a bidirectional iterator pointing to the one-past-last element of the list.

Definition at line 307 of file List.h.

◆ end() [2/2]

template<typename T , typename TAllocator >
ListIterator<const T> List< T, TAllocator >::end ( ) const
inline

Returns a bidirectional iterator pointing to the one-past-last element of the list.

Definition at line 312 of file List.h.

◆ erase()

template<typename T , typename TAllocator >
ListIterator<T> List< T, TAllocator >::erase ( const ListIterator< T >  iter)
inline

Removes an element given by the iterator.

This does not invalidate iterators or pointers to element, except for the iterator to the element being erased from the list.

Parameters
iterIterator to an element being erased. Must not be nullptr.
Returns
Iterator pointing to the next element, or nullptr if the removed element was the last one.

Definition at line 229 of file List.h.

◆ front() [1/2]

template<typename T , typename TAllocator >
INLINE T& List< T, TAllocator >::front ( )
inline

Returns the reference to the first element in the list.

Definition at line 262 of file List.h.

◆ front() [2/2]

template<typename T , typename TAllocator >
INLINE const T& List< T, TAllocator >::front ( ) const
inline

Returns the reference to the first element in the list.

Definition at line 268 of file List.h.

◆ insert()

template<typename T , typename TAllocator >
template<typename U >
void List< T, TAllocator >::insert ( const ListIterator< T >  iter,
U &&  value 
)
inline

Creates a new element and inserts it after the element given by the iterator.

Parameters
iterIterator to an element of the list. Must not be nullptr.

Definition at line 214 of file List.h.

◆ operator=()

template<typename T , typename TAllocator >
List& List< T, TAllocator >::operator= ( List< T, TAllocator > &&  other)
inline

Move operator.

Definition at line 163 of file List.h.

◆ pushBack()

template<typename T , typename TAllocator >
template<typename U >
void List< T, TAllocator >::pushBack ( U &&  value)
inline

Adds a new element to the back of the list.

Element is copied or moved, based on the type of the value.

Definition at line 189 of file List.h.

◆ pushFront()

template<typename T , typename TAllocator >
template<typename U >
void List< T, TAllocator >::pushFront ( U &&  value)
inline

Adds a new element to the beginning of the list.

Element is copied or moved, based on the type of the value.

Definition at line 202 of file List.h.

◆ size()

template<typename T , typename TAllocator >
INLINE Size List< T, TAllocator >::size ( ) const
inline

Returns the number of elements in the list.

Note that this is an O(N) operation, the number of elements is not cached.

Definition at line 177 of file List.h.

Friends And Related Function Documentation

◆ operator<<

template<typename T , typename TAllocator >
template<typename TStream >
TStream& operator<< ( TStream &  stream,
const List< T, TAllocator > &  array 
)
friend

Prints content of the list to stream. Stored values must have overloaded << operator.

Definition at line 328 of file List.h.


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