96#include <initializer_list>
100#include <type_traits>
116template<
class T ,
bool Pooled = true >
140 List( std::initializer_list< T > items );
143 template< std::input_iterator I , std::sentinel_for< I > S >
167 [[nodiscard]]
bool empty(
void )
const;
250 template<
bool Const >
259 using reference = std::conditional_t< Const , const T & , T & >;
261 using pointer = std::conditional_t< Const , const T * , T * >;
272 requires( Const && ! C )
305 [[nodiscard]]
Cell *
cell(
void )
const {
return( f_c ); }
308 Cell * f_c =
nullptr;
372 [[nodiscard]] std::size_t
size(
void )
const {
return( f_size ); }
395 [[nodiscard]]
const T &
get( std::size_t i )
const;
400 T
set( std::size_t i ,
const T & x );
406 void add( std::size_t i ,
const T & x );
533 template<
class C = std::less<> >
554 template<
class C = std::less<> >
560 [[nodiscard]]
bool linked(
void )
const;
564 [[nodiscard]]
bool owns(
Pos p )
const;
567 [[nodiscard]] Cell * sentinel(
void )
const;
571 void adopt(
List & o )
noexcept;
578 template<
class... Args >
579 Cell * make( Args &&... args ) {
580 return(
new Cell{ std::forward< Args >( args )... } );
583 void free( Cell * c )
noexcept {
delete c; }
585 void swap( Plain & )
noexcept { }
589 static void relink(
Cell * c ,
Cell * p )
noexcept;
594 static Cell * sortChain(
Cell * a , std::size_t k , C & less );
596 mutable Cell f_sentinel;
597 std::size_t f_size = 0;
600 std::conditional_t< Pooled , ObjectPool< Cell > , Plain > f_pool;
612#include "ADS/sequence/impl/List.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A pool of objects of one type, beyond the book: make() builds an object in a slot of the pool and fre...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
T value_type
the type of the items
Definition List.h:256
Iterator(Cell *c)
on the item of the cell , the end if is the sentinel
Definition List.h:268
std::conditional_t< Const, const T &, T & > reference
a reference to an item, constant if Const
Definition List.h:259
Iterator & operator++(void)
to the next cell
Definition List.h:280
Iterator & operator--(void)
to the previous cell
Definition List.h:291
Iterator(const Iterator< C > &o)
the const iterator from the other one
Definition List.h:273
std::bidirectional_iterator_tag iterator_category
the category of the iterator, bidirectional
Definition List.h:255
reference operator*(void) const
the item
Definition List.h:276
bool operator==(const Iterator &o) const =default
equal on the same cell
pointer operator->(void) const
the address of the item
Definition List.h:278
std::conditional_t< Const, const T *, T * > pointer
a pointer to an item, constant if Const
Definition List.h:261
Cell * cell(void) const
Definition List.h:305
std::ptrdiff_t difference_type
the type of the distances
Definition List.h:257
Iterator operator++(int)
to the next cell, returning the iterator before the step
Definition List.h:285
Iterator operator--(int)
to the previous cell, returning the iterator before the step
Definition List.h:296
Iterator(void)=default
an iterator on no cell
void write(Pos p, const T &v)
writes in the position
reverse_iterator rbegin(void)
the iterator on the last item, backwards
Definition List.h:347
iterator end(void)
the iterator past the last item
Definition List.h:333
reverse_iterator rend(void)
the iterator before the first item, backwards
Definition List.h:351
T erase(std::size_t i)
removes the item of rank and returns it,
List(std::initializer_list< T > items)
the list of the given items, in their order
void absorb(List &l2)
the items of l2 appended to this list in their order, l2 left empty, in by relinking (exercise 3....
bool operator==(const List &o) const
the same items in the same order
Pos remove(Pos p)
removes the item in the position , returning the position of its successor, which is now in its place
const_reverse_iterator rend(void) const
the constant iterator before the first item, backwards
Definition List.h:359
Iterator< true > const_iterator
Definition List.h:324
bool finished(Pos p) const
true if is or , i.e., the sentinel
Cell * Pos
Definition List.h:132
const Pair & const_reference
Definition List.h:320
List(const List &other)
a copy of other, cell by cell
List deal(void)
the items of odd rank moved, in their order, to the list returned (exercise 3.11 of Morin's book),
List & operator=(List other) noexcept
the items of other, by copy and swap
const_iterator begin(void) const
the constant iterator on the first item
Definition List.h:335
void mergeSort(C less=C())
sorts the list, stable, by the merge sort of exercise 3.13 of Morin's book: the list cut in two halve...
List truncate(std::size_t i)
the items of ranks cut off into the list returned, in by relinking (exercise 3.9 of Morin's book; i...
void reverse(void)
the order of the items reversed, by exchanging the two links of each cell and of the sentinel,...
Pos next(Pos p) const
the position of the item that follows
const_iterator cend(void) const
the constant iterator past the last item
Definition List.h:345
const_iterator end(void) const
the constant iterator past the last item
Definition List.h:339
List(List &&other) noexcept
the cells of other, which is left empty, in time
std::size_t size(void) const
the number of items, kept
Definition List.h:372
void add(std::size_t i, const T &x)
put at the rank , before the cell of rank ,
bool isPalindrome(void) const
true if the item of rank equals that of rank for every , by two walks from the two ends,...
static List merge(List &l1, List &l2, C less=C())
the merge of the two sorted lists l1 and l2, which are left empty, stable (the items of l1 first amon...
Pair & reference
Definition List.h:318
Pair value_type
Definition List.h:312
const_iterator cbegin(void) const
the constant iterator on the first item
Definition List.h:343
Pos head(void) const
the position of the first item
std::reverse_iterator< iterator > reverse_iterator
Definition List.h:326
Pos tail(void) const
the position of the last item
Pos insert(Pos p, const T &v)
puts in the position , i.e., before the item in , and returns its position
std::size_t size_type
Definition List.h:314
Pair Item
Definition List.h:122
const T & get(std::size_t i) const
the item of rank ,
void push_front(const T &v)
at the front, for std::front_inserter
Pos position(std::size_t i) const
the cell of rank , the sentinel for , reached from the nearer end in (Morin's getNode( i ))
void swap(List &other) noexcept
exchanges the cells with other, relinking them to the sentinels in time
bool empty(void) const
true if the list is empty, i.e., the sentinel is its own successor
const_reverse_iterator rbegin(void) const
the constant iterator on the last item, backwards
Definition List.h:355
List(I first, S last)
the list of the items of [ first , last ), in their order
void checkSize(void) const
counts the cells and throws std::logic_error if they are not the size kept (exercise 3....
const T & read(Pos p) const
the item in the position
void push_back(const T &v)
at the end, for std::back_inserter
List(void)
the empty list: the sentinel alone, its own predecessor and successor
Iterator< false > iterator
Definition List.h:322
void takeFirst(List &l2)
the first cell of l2 moved to the end of this list, by relinking (a new cell with the item moved if P...
void rotate(std::size_t r)
the item of rank moved to the rank by moving the sentinel before the item of rank ,...
Pos prev(Pos p) const
the position of the item that precedes
iterator begin(void)
the iterator on the first item
Definition List.h:331
std::ptrdiff_t difference_type
Definition List.h:316
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition List.h:328
T set(std::size_t i, const T &x)
written at the rank , the old item returned,
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
a cell of the list: the sentinel is a Cell with no meaningful value
Definition List.h:126
Cell * pred
the predecessor
Definition List.h:127
T value
the item
Definition List.h:129
Cell * succ
the successor
Definition List.h:128