Implements a doubly linked list, likewise std::list
does. Memory for inserted elements is allocated using the Allocator provided with construction.
Elements that are erased from the list will be recycled with subsequent insert operations. With that, remove and insert operations do not lead to leaked memory when a monotonic allocator is used.
It is allowed to use different allocator objects with insertions. However, the life-cycle of the allocated memory and the objects stored in this container has to be kept in sync by the user of this object. For more information on this topic see methods Clear and Reset.
#include <list.hpp>
Inner Type Index: | |
struct | TIterator |
Public Type Index: | |
using | AllocatorType = TAllocator |
The allocator type that TAllocator specifies. | |
using | ConstIterator = TIterator<const T> |
The constant iterator exposed by this container. | |
using | ConstReverseIterator = std::reverse_iterator<ConstIterator> |
The constant iterator exposed by this container. | |
using | Iterator = TIterator< T> |
The mutable iterator exposed by this container. | |
using | ReverseIterator = std::reverse_iterator<Iterator> |
The mutable iterator exposed by this container. | |
using | SharedRecyclerType |
Public Method Index: | |
std::iterator_traits Interface | |
Iterator | begin () |
Iterator | end () |
ConstIterator | begin () const |
ConstIterator | end () const |
ConstIterator | cbegin () const |
ConstIterator | cend () const |
ReverseIterator | rbegin () |
ReverseIterator | rend () |
ConstReverseIterator | rbegin () const |
ConstReverseIterator | rend () const |
ConstReverseIterator | crbegin () const |
ConstReverseIterator | crend () const |
List () | |
List (std::initializer_list< T > initList) | |
List (const List ©) | |
List (List &&move) | |
List (AllocatorType &pAllocator) | |
List (AllocatorType &pAllocator, std::initializer_list< T > initList) | |
template<typename TSharedRecycler = SharedRecyclerType, ATMP_T_IF(int, !ATMP_EQ(TSharedRecycler, void)) = 0> | |
List (TSharedRecycler &pSharedRecycler) | |
template<typename TSharedRecycler = SharedRecyclerType, ATMP_T_IF(int, !ATMP_EQ(TSharedRecycler, void)) = 0> | |
List (TSharedRecycler &pSharedRecycler, std::initializer_list< T > initList) | |
~List () | |
Destructor. Invokes Clear. | |
Allocation | |
AllocatorType & | GetAllocator () |
integer | RecyclablesCount () const |
Size and Capacity | |
integer | Count () const |
bool | IsEmpty () const |
bool | IsNotEmpty () const |
void | Clear () |
void | Reset () |
void | ReserveRecyclables (integer qty, lang::ValueReference reference) |
Element Access | |
T & | ElementAt (integer idx) |
const T & | ElementAt (integer idx) const |
T & | Front () |
const T & | Front () const |
T & | Back () |
const T & | Back () const |
Element Insertion | |
Iterator | Insert (ConstIterator position, const T ©) |
Iterator | Insert (ConstIterator position, T &&move) |
T & | PushBack (const T ©) |
T & | PushBack (T &&move) |
T & | PushFront (const T ©) |
T & | PushFront (T &&move) |
template<typename... TArgs> | |
Iterator | Emplace (ConstIterator position, TArgs &&... args) |
template<typename... TArgs> | |
T & | EmplaceBack (TArgs &&... args) |
template<typename... TArgs> | |
T & | EmplaceFront (TArgs &&... args) |
Element Removal | |
Iterator | Erase (ConstIterator position) |
Iterator | Erase (ConstIterator begin, ConstIterator end) |
void | PopFront () |
Removes the first element. | |
void | PopBack () |
Removes the last element. | |
Public Method Index: inherited from DbgCriticalSections | |
ALIB_FORCE_INLINE | DbgCriticalSections (const char *name) |
ALIB_FORCE_INLINE | ~DbgCriticalSections () |
Destructor. Checks that this instance is unused. | |
ALIB_API void | Acquire (const CallerInfo &ci) const |
ALIB_API void | AcquireShared (const CallerInfo &ci) const |
ALIB_API void | doAssert (bool cond, const CallerInfo &ciAssert, const CallerInfo &ci, const char *headline) const |
ALIB_API void | Release (const CallerInfo &ci) const |
ALIB_API void | ReleaseShared (const CallerInfo &ci) const |
ALIB_FORCE_INLINE void | yieldOrSleep () const |
Protected Type Index: | |
using | allocBase = lang::AllocatorMember<TAllocator> |
The allocator type that TAllocator specifies. | |
using | Element = detail::ListElement<T> |
The list element type. | |
using | hook = lang::BidiListHook<detail::ListElement<T>> |
The allocator type that TAllocator specifies. | |
using | recyclerType |
The recycler type. | |
Additional Inherited Members | |
Public Static Field Index: inherited from DbgCriticalSections | |
static ALIB_API const char * | ASSERTION_FORMAT |
Public Field Index: inherited from DbgCriticalSections | |
CallerInfo | DCSAcq |
Source location of acquirement. | |
AssociatedLock * | DCSLock {nullptr} |
const char * | DCSName |
The name of this DCS. Used for debug-output. | |
std::atomic< int > | DCSReaderCnt {0} |
Tracks enter/exit calls of readers. | |
CallerInfo | DCSRel |
Source location of the last "reader" seen. | |
CallerInfo | DCSSAcq |
Source location of acquirement. | |
CallerInfo | DCSSRel |
Source location of the last "reader" seen. | |
std::atomic< int > | DCSWriterCnt {0} |
Tracks enter/exit calls (including readers) | |
int | DCSYieldOrSleepTimeInNS = -1 |
Private Type Index: inherited from BidiListHook< detail::ListElement< T > > | |
using | TFNode |
An alias for the base type of the node type of this list. | |
using | TNode |
An alias for the node type of this list. | |
Private Field Index: inherited from BidiListHook< detail::ListElement< T > > | |
TNode | hook |
The root node. Points twice to itself when the list is empty. | |
Private Method Index: inherited from BidiListHook< detail::ListElement< T > > | |
BidiListHook () noexcept | |
Default constructor. Initializes this list to be empty. | |
BidiListHook (BidiListHook &&move) noexcept | |
BidiListHook (const BidiListHook &)=delete | |
Deleted copy constructor. | |
BidiListHook (detail::ListElement< T > *first) noexcept | |
BidiListHook (detail::ListElement< T > *first, detail::ListElement< T > *last) noexcept | |
integer | count (const TNode *end=nullptr) const noexcept |
detail::ListElement< T > * | end () const noexcept |
detail::ListElement< T > * | first () const noexcept |
bool | isEmpty () const noexcept |
bool | isFirst (const detail::ListElement< T > *elem) const noexcept |
bool | isLast (const detail::ListElement< T > *elem) const noexcept |
detail::ListElement< T > * | last () const noexcept |
BidiListHook & | operator= (BidiListHook &&) noexcept=default |
BidiListHook & | operator= (const BidiListHook &)=delete |
detail::ListElement< T > * | popEnd () noexcept |
detail::ListElement< T > * | popFront () noexcept |
void | pushEnd (detail::ListElement< T > *elem) noexcept |
void | pushEnd (detail::ListElement< T > *first, detail::ListElement< T > *last) noexcept |
void | pushFront (detail::ListElement< T > *elem) noexcept |
void | pushFront (detail::ListElement< T > *first, detail::ListElement< T > *last) noexcept |
void | reset () noexcept |
Resets this list to zero elements. | |
using AllocatorType = TAllocator |
|
protected |
using ConstIterator = TIterator<const T> |
using ConstReverseIterator = std::reverse_iterator<ConstIterator> |
|
protected |
|
protected |
|
protected |
using ReverseIterator = std::reverse_iterator<Iterator> |
using SharedRecyclerType |
This type definition may be used to define an externally managed shared recycler, which can be passed to the alternative constructor of this class when template parameter TRecycling equals Shared.
|
inline |
Constructor neither requiring an allocator, nor a shared recycler.
|
inline |
Constructor that takes an initializer list, but neither a n allocator, nor a shared recycler.
initList | The initial lists of elements to add. |
Definition at line 321 of file list.hpp.
|
inline |
Constructor accepting an allocator.
pAllocator | The allocator to use. |
|
inline |
Constructor that takes an allocator and an initializer list.
pAllocator | The allocator to use. |
initList | The initial lists of elements to add. |
Definition at line 383 of file list.hpp.
|
inline |
Constructor taking a shared recycler and an initializer list. This constructor is not available if the template argument TRecycling does not equal Shared.
pSharedRecycler | The shared recycler. |
initList | The initial lists of elements to add. |
Definition at line 415 of file list.hpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Invokes the destructor of all elements and empties the list. All allocated internal elements are kept for future recycling. Hence, the invocation of this method with this value implies that an associated monotonic allocator is not reset.
As the life-cycle of the monotonic allocator(s) used for insertions is not under control of this object, it is the obligation of the caller to ensure that the monotonic allocator is kept in sync with this object.
Definition at line 491 of file list.hpp.
|
inline |
|
inline |
|
inline |
Adds a new element before the given position.
TArgs | Types of variadic parameters given with parameter args. |
position | The position to emplace the new element. |
args | Variadic parameters to be forwarded to the constructor of type T. |
Definition at line 730 of file list.hpp.
|
inline |
Adds a new element at the end of the list.
TArgs | Types of variadic parameters given with parameter args. |
args | Variadic parameters to be forwarded to the constructor of type T. |
Definition at line 746 of file list.hpp.
|
inline |
Adds a new element at the end of the list.
TArgs | Types of variadic parameters given with parameter args. |
args | Variadic parameters to be forwarded to the constructor of type T. |
Definition at line 762 of file list.hpp.
|
inline |
|
inline |
Removes a range of elements defined by iterators first and last.
begin | The start of the range to remove. |
end | The first element behind the range to remove. |
Definition at line 806 of file list.hpp.
|
inline |
Removes an element at the given position.
position | A constant iterator pointing to the element to be removed. Mutable iterators are inherently converted with the invocation of this method. |
Definition at line 784 of file list.hpp.
|
inline |
|
inline |
|
inline |
Returns the allocator of this object. Usually the allocator might be used to perform allocations in respect to data found in objects stored in this object. However, such allowance is dependent on the use case and not part of this class's contract.
Definition at line 442 of file list.hpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Counts the number of currently allocated but unused (not contained) list elements that will be recycled with upcoming insertions.
|
inline |
|
inline |
|
inline |
Allocates the required memory for the number of additional elements expected.
qty | The expected resulting number (or increase) of elements to be stored in this container. |
reference | Denotes whether qty is meant as an absolute size or an increase. |
Definition at line 532 of file list.hpp.
|
inline |
Same as clear, but does not recycle internal nodes. Furthermore, all recyclables are deleted. The latter is done only if recycling type is not Shared. In this case, the elements are still recycled.
This method is useful with monotonic allocators, that can be reset as well, after this instance is reset. But, because the life-cycle of the monotonic allocator(s) used for insertions is not under control of this object, it is the obligation of the caller to ensure that the monotonic allocator is kept in sync with this object.
Definition at line 512 of file list.hpp.