Template Class SinglyList

Nested Relationships

Nested Types

Class Documentation

template<class T>
class SinglyList

a SEQUENCE realized as a singly linked list with no sentinel

Public Types

using Item = T

the type of the items

using Pos = Cell*

the cell before the item, nil for the first one

using value_type = T
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = T&
using const_reference = const T&
using iterator = Iterator<false>
using const_iterator = Iterator<true>

Public Functions

SinglyList(void) = default
SinglyList(std::initializer_list<T> items)

the list of the given items, in their order

SinglyList(const SinglyList &other)
SinglyList(SinglyList &&other) noexcept

the cells of other, which is left empty

SinglyList &operator=(SinglyList other) noexcept
~SinglyList()
void swap(SinglyList &other) noexcept
bool empty(void) const
bool finished(Pos p) const

true on \( pos_{-1} \) and on \( pos_n \), the address of the last cell (nil if the list is empty)

Pos head(void) const

\( pos_0 \), i.e., nil

Pos tail(void) const

the position of the last item, O( n )

Pos next(Pos p) const

the position that follows p

Pre:

p is not \( pos_n \)

Pos prev(Pos p) const

the position that precedes p, O( n )

Pos insert(Pos p, const T &v)

puts v in position p, i.e., before the item in p; the new item takes the position p

Pre:

p is not \( pos_{-1} \)

Post:

read( p ) is v

Pos remove(Pos p)

removes the item in position p, whose successor takes the position p

Pre:

p holds an item

const T &read(Pos p) const
Pre:

p holds an item

void write(Pos p, const T &v)
Pre:

p holds an item

Post:

read( p ) is v

bool operator==(const SinglyList &o) const

the same items in the same order

inline iterator begin(void)
inline iterator end(void)
inline const_iterator begin(void) const
inline const_iterator end(void) const
inline const_iterator cbegin(void) const
inline const_iterator cend(void) const
template<std::input_iterator I, std::sentinel_for<I> S>
SinglyList(I first, S last)

the list of the items of [ first , last ), in their order

void push_front(const T &v)

v at the front, for std::front_inserter

struct Cell

a cell of the list

Public Members

T value

the item

Cell *next

the next cell, nil after the last one

template<bool Const>
class Iterator

the iterator, on items const if Const

Public Types

using iterator_category = std::forward_iterator_tag
using value_type = T
using difference_type = std::ptrdiff_t
using reference = std::conditional_t<Const, const T&, T&>
using pointer = std::conditional_t<Const, const T*, T*>

Public Functions

Iterator(void) = default
inline explicit Iterator(Cell *c)
template<bool C>
inline Iterator(const Iterator<C> &o)

the const iterator from the other one

inline reference operator*(void) const
inline pointer operator->(void) const
inline Iterator &operator++(void)
inline Iterator operator++(int)
bool operator==(const Iterator &o) const = default