Containers

CList

A linked sequence with stable element positions and splice operations.

C++23 mc/CList.h
#include <mc/CList.h>

Standard-style names retain their familiar container meaning. The notes below explain lookup results, mutation, ownership, and Catalyst conveniences; only entirely obvious operations are left as declarations.

Exceptions escaping container operations are translated to CError. Direct iterator operations, element references, and calls through .std() follow the underlying type’s contracts.

Jump to a declaration · 85

CList

template<typename T, class Alloc = std::allocator<T>> class CList

Types, constants & data

using List = std::list<T, Alloc>;
using value_type = T;
using pointer = typename List::pointer;
using const_pointer = typename List::const_pointer;
using size_type = typename List::size_type;
using difference_type = typename List::difference_type;
using reference = typename List::reference;
using const_reference = typename List::const_reference;
using iterator = typename List::iterator;
using const_iterator = typename List::const_iterator;
using allocator_type = typename List::allocator_type;
using reverse_iterator = typename List::reverse_iterator;
using const_reverse_iterator = typename List::const_reverse_iterator;

Methods

CList

CList() noexcept(std::is_nothrow_default_constructible_v<List>);
explicit CList(const Alloc& alloc) noexcept;
explicit CList(size_type n, const Alloc& alloc = cContainerDefault<Alloc>());
CList(size_type n, const T& value, const Alloc& alloc = cContainerDefault<Alloc>());
template<CInputIterator I> CList(I first, I last, const Alloc& alloc = cContainerDefault<Alloc>());
CList(const CList& x);
CList(CList&& x) noexcept(std::is_nothrow_move_constructible_v<List>);
CList(const CList& x, const std::type_identity_t<Alloc>& alloc);
CList(CList&& x, const std::type_identity_t<Alloc>& alloc);
CList(const List& x);
CList(List&& x) noexcept(std::is_nothrow_move_constructible_v<List>);
CList(const List& x, const std::type_identity_t<Alloc>& alloc);
CList(List&& x, const std::type_identity_t<Alloc>& alloc);
CList(std::initializer_list<T> values, const Alloc& alloc = cContainerDefault<Alloc>());
template<CContainerRange<T> R> CList(std::from_range_t, R&& range, const Alloc& alloc = cContainerDefault<Alloc>());
CList(CBuffer& b);

Creates an empty sequence, copies a range or initializer list, or creates n elements with an optional repeated value. The count constructor changes size rather than merely reserving capacity; the CBuffer overload restores a typed serialized sequence.

fromArgs

template<class... Args> static CList fromArgs(Args&&... args);

Builds a container with one element per argument, in argument order. Arguments are forwarded so move-only values can be supplied as rvalues.

range

static CList range(int64_t a, int64_t b);
static CList range(size_t size);

Builds consecutive values in [a, b), or [0, size) for the one-argument form. These overloads require a nonempty range (a < b).

operator=

CList& operator=(const CList& x);
CList& operator=(CList&& x) noexcept(std::is_nothrow_move_assignable_v<List>);
CList<T, Alloc>& operator=(std::initializer_list<value_type> il);

assign

template<CInputIterator InputIterator> void assign(InputIterator first, InputIterator last);
void assign(size_type n, const T& u);
void assign(std::initializer_list<T> values);

Replaces all elements with the supplied count/value, iterator range, or initializer list. Existing element references and iterators may be invalidated.

assign_range

template<CContainerRange<T> R> void assign_range(R&& range);

Replaces the contents with the elements of a C++ range. Each range element must be convertible to the container element type.

begin

iterator begin() noexcept;
const_iterator begin() const noexcept;

cbegin

const_iterator cbegin() const noexcept;

end

iterator end() noexcept;
const_iterator end() const noexcept;

cend

const_iterator cend() const noexcept;

rbegin

reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;

crbegin

const_reverse_iterator crbegin() const noexcept;

rend

reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;

crend

const_reverse_iterator crend() const noexcept;

span

cspan span() const noexcept;
cspan span(size_t start) const noexcept;
cspan span(size_t start, size_t endOffset) const noexcept;

Returns an index range. start skips initial indices; endOffset excludes that many indices at the end.

empty

bool empty() const noexcept;

size

size_type size() const noexcept;

max_size

size_type max_size() const noexcept;

operator[]

reference& operator[](size_t i);
const_reference& operator[](size_t i) const;

Walks from begin() to the requested zero-based position and returns that element. This is a linear-time operation and requires an index below size().

front

reference front() noexcept(noexcept(l_.front()));
const_reference front() const noexcept(noexcept(l_.front()));

Returns the first element by reference. The container must be nonempty.

back

reference back() noexcept(noexcept(l_.back()));
const_reference back() const noexcept(noexcept(l_.back()));

Returns the last element by reference. The list must be nonempty.

find

iterator find(const T& v);

Returns an iterator to the first equal element, or end() when absent. The search is linear.

hasIndex

bool hasIndex(size_t i) const;

Tests whether the index is below size(), without accessing or adding an element.

has

bool has(const T& v) const;

Reports whether an equal element occurs in the container.

insert

iterator insert(const_iterator position, const T& x);
iterator insert(size_t index, const T& x);
iterator insert(const_iterator position, size_type n, const T& x);
template<CInputIterator InputIterator> iterator insert(const_iterator position, InputIterator first, InputIterator last);
iterator insert(const_iterator position, T&& value);
iterator insert(const_iterator position, std::initializer_list<T> values);

Inserts values before the supplied iterator position and returns an iterator to the first inserted element. Existing elements retain their iterators and references.

insert_range

template<CContainerRange<T> R> iterator insert_range(const_iterator position, R&& range);

Inserts the elements of a C++ range before the supplied iterator. Returns an iterator to the first inserted element, or the insertion position for an empty range.

emplace

template<class... Args> iterator emplace(const_iterator position, Args&&... args);

Constructs an element before the given position from forwarded constructor arguments. Returns its iterator.

operator<<

template<class S> CList& operator<<(S&& x);

Appends one element and returns this container, allowing chained appends.

push_back

void push_back(const T& x);
void push_back(T&& x);

emplace_back

template <class... Args> reference emplace_back(Args&&... args);

Constructs an element at the end from forwarded constructor arguments and returns a reference to it.

append

void append(const CList& l);
template<class S> void append(const CList<S>& l);

Appends the supplied container’s elements in order. The original contents remain at the beginning.

append_range

template<CContainerRange<T> R> void append_range(R&& range);

Adds a C++ range at the end, preserving the order of its elements. Existing contents remain at the beginning.

push_front

void push_front(const T& x);
void push_front(T&& value);

emplace_front

template <class... Args> reference emplace_front(Args&&... args);

Constructs an element at the beginning from forwarded constructor arguments and returns a reference to it.

prepend_range

template<CContainerRange<T> R> void prepend_range(R&& range);

Adds a C++ range at the beginning, preserving the range’s order before the existing elements.

erase

iterator erase(size_t index);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);

Removes an element or iterator range and returns the following iterator. The numeric-index overload walks from the beginning to find the position, so it is linear in the index.

pop_back

void pop_back() noexcept(noexcept(l_.back()));

Removes the last element without returning it. The container must be nonempty; use popBack() to retain its value.

popBack

T popBack();

Removes and returns the last element. The container must be nonempty.

pop_front

void pop_front() noexcept(noexcept(l_.front()));

Removes the first element without returning it. The container must be nonempty; use popFront() to retain its value.

popFront

T popFront();

Removes and returns the first element. The container must be nonempty.

clear

void clear() noexcept;

clearExcept

template<class S> void clearExcept(const S& s);

Removes every element for which s.has(element) is false. The surviving elements retain their relative order.

resize

void resize(size_type n);
void resize(size_type n, const T& value);

Changes the number of elements, removing trailing elements or appending default/value-initialized elements. It changes size(), unlike reserve().

swap

void swap(CList& lst) noexcept(noexcept(l_.swap(lst.l_)));

merge

void merge(CList& x);
template<class Compare> void merge(CList& x, Compare comp);
void merge(CList&& source);
template<class Compare> void merge(CList&& source, Compare compare);

Transfers elements from a list sorted with the same comparison into this sorted list. The source is emptied; compatible allocators are required.

splice

void splice(const_iterator position, CList& x);
void splice(const_iterator position, CList& x, const_iterator i);
void splice(const_iterator position, CList& x, const_iterator first, const_iterator last);
void splice(const_iterator position, CList&& source);
void splice(const_iterator position, CList&& source, const_iterator item);
void splice(const_iterator position, CList&& source, const_iterator first, const_iterator last);

Transfers all, one, or a range of nodes from another list before the destination position. Elements are not copied, and iterators to transferred elements continue to refer to them; allocators must be compatible.

remove

size_type remove(const T& value);

Removes all elements equal to the supplied value and returns the number removed.

remove_if

template <class Predicate> size_type remove_if(Predicate pred);

Removes all elements for which the predicate returns true and returns the number removed.

unique

size_type unique();
template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);

Removes consecutive equivalent elements and returns the number removed. Sort first if the intention is to eliminate equal values throughout the list.

sort

void sort();
template<class Compare> void sort(Compare comp);

Stably sorts the list using the supplied comparison, or element ordering by default. Existing element references and iterators remain valid.

reverse

void reverse() noexcept;

Reverses list order in place while preserving the elements and their references.

std

const List& std() const noexcept;
List& std() noexcept;

Returns a reference to the underlying standard container. Mutations affect this object directly; calls through that reference bypass Catalyst exception translation.

operator const List&

operator const List&() const noexcept;

Borrows the underlying container for interoperability. This does not copy storage; references and iterators follow that container’s lifetime and invalidation rules.

operator List&

operator List&() noexcept;

Borrows the underlying container for interoperability. This does not copy storage; references and iterators follow that container’s lifetime and invalidation rules.

store

void store(CBuffer& b) const;

Appends the container to a CBuffer; restore it with the buffer-taking constructor.

dump

cstr dump() const;

Returns the stream-formatted representation as a cstr; this is display text rather than the binary storage format.

Free functions & types

Functions

swap

template<class T, class A> void swap(CList<T, A>& x, CList<T, A>& y) noexcept(noexcept(x.swap(y)));

operator<<

template<class T, class A> inline std::ostream& operator<<(std::ostream& ostr, const CList<T, A>& v);

erase

template<class T, class A, class U> typename CList<T, A>::size_type erase(CList<T, A>& values, const U& value);

Removes all elements equal to the supplied value and returns the number removed.

erase_if

template<class T, class A, class Predicate> typename CList<T, A>::size_type erase_if(CList<T, A>& values, Predicate predicate);

Removes every element for which the predicate returns true and returns the number removed.

<deduction guide for CList>

template<CInputIterator I, class Alloc = std::allocator<typename std::iterator_traits<I>::value_type>> CList(I, I, Alloc = cContainerDefault<Alloc>()) -> CList<typename std::iterator_traits<I>::value_type, Alloc>;
template<std::ranges::input_range R, class Alloc = std::allocator<std::ranges::range_value_t<R>>> CList(std::from_range_t, R&&, Alloc = cContainerDefault<Alloc>()) -> CList<std::ranges::range_value_t<R>, Alloc>;
template<class T, class Alloc = std::allocator<T>> CList(std::initializer_list<T>, Alloc = cContainerDefault<Alloc>()) -> CList<T, Alloc>;

pmr

Types, constants & data

template<class T> using CList = mc::CList<T, std::pmr::polymorphic_allocator<T>>;