CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
List< T > Class Template Reference

List data container More...

#include <cc/List>

Public Types

using Item = T
 Item type.
 

Standard Iterators

using value_type = Item
 Item value type.
 
using size_type = long
 Type of the container capacity.
 
using iterator = Iterator<BucketVector<Item>>
 Value iterator.
 
using const_iterator = Iterator<const BucketVector<Item>>
 Readonly value iterator.
 
using reverse_iterator = ReverseIterator<BucketVector<Item>>
 Reverse value iterator.
 
using const_reverse_iterator = ReverseIterator<const BucketVector<Item>>
 Readonly reverse value iterator.
 
iterator begin ()
 Return iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 
using Tree = BucketVector<Item>
 
const Tree & tree () const
 

Construction and Assignment

 List ()=default
 Construct an empty list.
 
 List (const List &other)=default
 Construct a copy of other.
 
 List (std::initializer_list< Item > items)
 Construct with initial items.
 
 List (std::initializer_list< List > lists)
 Initialize by joining initial lists.
 
 List (List &&other)
 Take over the right-side list other.
 
Listoperator= (const List &other)=default
 Assign list other.
 
Listoperator= (List &&other)
 Assign right-side list other.
 

Item Access

Locator head () const
 Get a locator pointing to the first item.
 
Locator tail () const
 Get a locator pointing to the last item.
 
Locator from (long index) const
 Get a locator pointing to the item at index.
 
long count () const
 Get the number of items stored in the list.
 
long size () const
 Get the number of items stored in the list.
 
bool has (long i) const
 Check if i is a valid index.
 
 operator bool () const
 Check if this list is non-empty.
 
long operator+ () const
 Get the number of items stored in the list.
 
const Itemat (Locator pos) const
 Get constant reference to the item at position pos.
 
const Itemat (long index) const
 Get constant reference to the item at index.
 
ItemmutableAt (Locator pos)
 Get reference to the item at position pos.
 
ItemmutableAt (long index)
 Get reference to the item at index.
 
const Itemoperator[] (long index) const
 Get constant reference to the item at index.
 
Itemoperator[] (long index)
 Get reference to the item at index.
 
Item operator() (long index) const
 Get value at index if 0 <= index && index < count(), otherwise return fallback.
 
Listoperator() (long index, const T &value)
 Set value at index if 0 <= i && i < count(), otherwise do nothing.
 
const Itemfirst () const
 Get constant reference to first item.
 
const Itemlast () const
 Get constant reference to last item.
 
bool firstIs (const Item &item) const
 Tell if item is the first item.
 
bool lastIs (const Item &item) const
 Tell if item is the last item.
 
ItemtouchFirst ()
 Get reference to first item.
 
ItemtouchLast ()
 Get reference to last item.
 

Front and Back Operations

void append (const Item &item)
 Insert item at the end of the list.
 
void prepend (const Item &item)
 Insert item at the beginning of the list.
 
template<class Item >
void appendList (const List< Item > &other)
 Append a copy of list other.
 
template<class Item >
void prependList (const List< Item > &other)
 Prepend a copy of list other.
 
void pushBack (const Item &item)
 Insert item as a new last item.
 
void pushFront (const Item &item)
 Insert item as a new first item.
 
void popBack ()
 Remove the last item.
 
void popFront ()
 Remove the first item.
 
template<class... Args>
void emplaceBack (Args... args)
 Insert a new last item.
 
template<class... Args>
void emplaceFront (Args... args)
 Emplace a new first item.
 
Listoperator<< (const Item &item)
 Append item.
 
Listoperator>> (Item &item)
 Remove and return the first item.
 

Positional Operations

void insertAt (Locator &pos, const Item &item)
 Insert item at position pos.
 
void insertAt (long index, const Item &item)
 Insert item at index.
 
void removeAt (Locator &pos)
 Remove item at position pos (and advance pos to the next item)
 
void removeAt (long index)
 Remove item at index.
 
template<class... Args>
void emplaceAt (Locator &pos, Args... args)
 Create a new item at position pos (initialized with args)
 
template<class... Args>
void emplaceAt (long index, Args... args)
 Create a new item at index (initialized with args)
 

Global Operations

template<class Pattern >
bool find (const Pattern &pattern, InOut< Locator > pos=None{}) const
 Find item b.
 
template<class Pattern >
bool contains (const Pattern &pattern) const
 Convenience method.
 
template<class Pattern >
void replace (const Pattern &pattern, const Item &substitute)
 Replace all occurences of pattern by substitute.
 
template<class Order = DefaultOrder>
void sort ()
 Sort the list in-situ.
 
template<class Order = DefaultOrder>
void sortUnique ()
 Sorts the list and removes all doubles.
 
List sorted () const
 Return a sorted copy of this list
 
List sortedUnique () const
 Return a sorted copy of this list which does not contain repeated items
 
void reverse ()
 Reverse the order of items in the list
 
List reversed () const
 Return a copy of the list in which the order of items is reversed
 
template<class F >
void forEach (F f) const
 Call function f for each item
 
template<class F >
void forEach (F f)
 Call function f for each item
 
void deplete ()
 Remove all items.
 
template<class R = T, class S = T>
join (S sep) const
 Merge into a single item interspersed by sep.
 
template<class R = T>
join () const
 Merge into a single item.
 

Comparism Operators

template<class Other >
bool operator== (const Other &other) const
 Equality operator.
 
template<class Other >
std::strong_ordering operator<=> (const Other &other) const
 Ordering operator.
 

Detailed Description

template<class T>
class cc::List< T >

List data container

Template Parameters
TItem type
Todo
List::allocate(long)

Member Typedef Documentation

◆ Item

template<class T >
using Item = T

Item type.

◆ value_type

template<class T >
using value_type = Item

Item value type.

◆ size_type

template<class T >
using size_type = long

Type of the container capacity.

◆ iterator

template<class T >
using iterator = Iterator<BucketVector<Item>>

Value iterator.

◆ const_iterator

template<class T >
using const_iterator = Iterator<const BucketVector<Item>>

Readonly value iterator.

◆ reverse_iterator

template<class T >
using reverse_iterator = ReverseIterator<BucketVector<Item>>

Reverse value iterator.

◆ const_reverse_iterator

template<class T >
using const_reverse_iterator = ReverseIterator<const BucketVector<Item>>

Readonly reverse value iterator.

Constructor & Destructor Documentation

◆ List() [1/5]

template<class T >
List ( )
default

Construct an empty list.

◆ List() [2/5]

template<class T >
List ( const List< T > & other)
default

Construct a copy of other.

◆ List() [3/5]

template<class T >
List ( std::initializer_list< Item > items)

Construct with initial items.

◆ List() [4/5]

template<class T >
List ( std::initializer_list< List< T > > lists)

Initialize by joining initial lists.

◆ List() [5/5]

template<class T >
List ( List< T > && other)

Take over the right-side list other.

Member Function Documentation

◆ operator=() [1/2]

template<class T >
List & operator= ( const List< T > & other)
default

Assign list other.

◆ operator=() [2/2]

template<class T >
List & operator= ( List< T > && other)

Assign right-side list other.

◆ head()

template<class T >
Locator head ( ) const

Get a locator pointing to the first item.

◆ tail()

template<class T >
Locator tail ( ) const

Get a locator pointing to the last item.

◆ from()

template<class T >
Locator from ( long index) const

Get a locator pointing to the item at index.

◆ count()

template<class T >
long count ( ) const

Get the number of items stored in the list.

◆ size()

template<class T >
long size ( ) const

Get the number of items stored in the list.

◆ has()

template<class T >
bool has ( long i) const

Check if i is a valid index.

◆ operator bool()

template<class T >
operator bool ( ) const
explicit

Check if this list is non-empty.

◆ operator+()

template<class T >
long operator+ ( ) const

Get the number of items stored in the list.

◆ at() [1/2]

template<class T >
const Item & at ( Locator pos) const

Get constant reference to the item at position pos.

◆ at() [2/2]

template<class T >
const Item & at ( long index) const

Get constant reference to the item at index.

◆ mutableAt() [1/2]

template<class T >
Item & mutableAt ( Locator pos)

Get reference to the item at position pos.

◆ mutableAt() [2/2]

template<class T >
Item & mutableAt ( long index)

Get reference to the item at index.

◆ operator[]() [1/2]

template<class T >
const Item & operator[] ( long index) const

Get constant reference to the item at index.

◆ operator[]() [2/2]

template<class T >
Item & operator[] ( long index)

Get reference to the item at index.

◆ operator()() [1/2]

template<class T >
Item operator() ( long index) const

Get value at index if 0 <= index && index < count(), otherwise return fallback.

◆ operator()() [2/2]

template<class T >
List & operator() ( long index,
const T & value )

Set value at index if 0 <= i && i < count(), otherwise do nothing.

◆ first()

template<class T >
const Item & first ( ) const

Get constant reference to first item.

◆ last()

template<class T >
const Item & last ( ) const

Get constant reference to last item.

◆ firstIs()

template<class T >
bool firstIs ( const Item & item) const

Tell if item is the first item.

◆ lastIs()

template<class T >
bool lastIs ( const Item & item) const

Tell if item is the last item.

◆ touchFirst()

template<class T >
Item & touchFirst ( )

Get reference to first item.

◆ touchLast()

template<class T >
Item & touchLast ( )

Get reference to last item.

◆ append()

template<class T >
void append ( const Item & item)

Insert item at the end of the list.

◆ prepend()

template<class T >
void prepend ( const Item & item)

Insert item at the beginning of the list.

◆ appendList()

template<class T >
template<class Item >
void appendList ( const List< Item > & other)

Append a copy of list other.

◆ prependList()

template<class T >
template<class Item >
void prependList ( const List< Item > & other)

Prepend a copy of list other.

◆ pushBack()

template<class T >
void pushBack ( const Item & item)

Insert item as a new last item.

◆ pushFront()

template<class T >
void pushFront ( const Item & item)

Insert item as a new first item.

◆ popBack()

template<class T >
void popBack ( )

Remove the last item.

◆ popFront()

template<class T >
void popFront ( )

Remove the first item.

◆ emplaceBack()

template<class T >
template<class... Args>
void emplaceBack ( Args... args)

Insert a new last item.

Parameters
argsconstruction arguments

◆ emplaceFront()

template<class T >
template<class... Args>
void emplaceFront ( Args... args)

Emplace a new first item.

Parameters
argsconstruction arguments

◆ operator<<()

template<class T >
List & operator<< ( const Item & item)

Append item.

◆ operator>>()

template<class T >
List & operator>> ( Item & item)

Remove and return the first item.

◆ insertAt() [1/2]

template<class T >
void insertAt ( Locator & pos,
const Item & item )

Insert item at position pos.

◆ insertAt() [2/2]

template<class T >
void insertAt ( long index,
const Item & item )

Insert item at index.

◆ removeAt() [1/2]

template<class T >
void removeAt ( Locator & pos)

Remove item at position pos (and advance pos to the next item)

◆ removeAt() [2/2]

template<class T >
void removeAt ( long index)

Remove item at index.

◆ emplaceAt() [1/2]

template<class T >
template<class... Args>
void emplaceAt ( Locator & pos,
Args... args )

Create a new item at position pos (initialized with args)

◆ emplaceAt() [2/2]

template<class T >
template<class... Args>
void emplaceAt ( long index,
Args... args )

Create a new item at index (initialized with args)

◆ find()

template<class T >
template<class Pattern >
bool find ( const Pattern & pattern,
InOut< Locator > pos = None{} ) const

Find item b.

Template Parameters
PatternPattern type
Parameters
patternThe pattern to search for
posProvides the starting position and returns the final position
Returns
True if item b was found, false otherwise

◆ contains()

template<class T >
template<class Pattern >
bool contains ( const Pattern & pattern) const

Convenience method.

Template Parameters
PatternPattern type
Parameters
patternThe pattern to search for

◆ replace()

template<class T >
template<class Pattern >
void replace ( const Pattern & pattern,
const Item & substitute )

Replace all occurences of pattern by substitute.

◆ sort()

template<class T >
template<class Order = DefaultOrder>
void sort ( )

Sort the list in-situ.

Template Parameters
OrderSort ordering

Sorts the list according the given sort ordering. The order of equal elements is preserved.

◆ sortUnique()

template<class T >
template<class Order = DefaultOrder>
void sortUnique ( )

Sorts the list and removes all doubles.

Template Parameters
OrderSorting order

Sorts the list of items according the given sorting order and removes all doubles thereafter.

◆ sorted()

template<class T >
List sorted ( ) const

Return a sorted copy of this list

Returns
sorted copy of this list

The order of equal elements is preserved.

◆ sortedUnique()

template<class T >
List sortedUnique ( ) const

Return a sorted copy of this list which does not contain repeated items

Returns
sorted copy of this list

For repeated items only the first occurance is added to the sorted list.

◆ reverse()

template<class T >
void reverse ( )

Reverse the order of items in the list

◆ reversed()

template<class T >
List reversed ( ) const

Return a copy of the list in which the order of items is reversed

◆ forEach() [1/2]

template<class T >
template<class F >
void forEach ( F f) const

Call function f for each item

Template Parameters
FFunction type (lambda or functor)
Parameters
fUnary function which gets called for each item

◆ forEach() [2/2]

template<class T >
template<class F >
void forEach ( F f)

Call function f for each item

Template Parameters
FFunction type (lambda or functor)
Parameters
fUnary function which gets called for each item

◆ deplete()

template<class T >
void deplete ( )

Remove all items.

◆ join() [1/2]

template<class T >
template<class R = T, class S = T>
R join ( S sep) const

Merge into a single item interspersed by sep.

◆ join() [2/2]

template<class T >
template<class R = T>
R join ( ) const

Merge into a single item.

◆ begin() [1/2]

template<class T >
iterator begin ( )

Return iterator pointing to the first item (if any)

◆ end() [1/2]

template<class T >
iterator end ( )

Return iterator pointing behind the last item

◆ begin() [2/2]

template<class T >
const_iterator begin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ cbegin()

template<class T >
const_iterator cbegin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ end() [2/2]

template<class T >
const_iterator end ( ) const

Return readonly iterator pointing behind the last item

◆ cend()

template<class T >
const_iterator cend ( ) const

Return readonly iterator pointing behind the last item

◆ rbegin() [1/2]

template<class T >
reverse_iterator rbegin ( )

Return reverse iterator pointing to the last item (if any)

◆ rend() [1/2]

template<class T >
reverse_iterator rend ( )

Return reverse iterator pointing before the first item

◆ rbegin() [2/2]

template<class T >
const_reverse_iterator rbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ crbegin()

template<class T >
const_reverse_iterator crbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ rend() [2/2]

template<class T >
const_reverse_iterator rend ( ) const

Return reverse iterator pointing before the first item

◆ crend()

template<class T >
const_reverse_iterator crend ( ) const

Return reverse iterator pointing before the first item

◆ operator==()

template<class T >
template<class Other >
bool operator== ( const Other & other) const

Equality operator.

◆ operator<=>()

template<class T >
template<class Other >
std::strong_ordering operator<=> ( const Other & other) const

Ordering operator.