Containers

CSVector

A bounded vector that stores a variable number of elements within a fixed capacity.

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

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

The capacity is a template argument. Capacity overflow throws CLengthError; checked indexing throws COutOfRangeError.

Jump to a declaration · 46

CSVector

template<class T, uint32_t N> class CSVector

Types, constants & data

using value_type = T;
static constexpr uint32_t Size = N;

Methods

range

static CSVector range(T a, T b);
static CSVector range(T size);

Builds consecutive values in [a, b), or [0, size). The result must fit the fixed capacity N.

begin

iterator begin();
const_iterator begin() const;

end

iterator end();
const_iterator end() const;

span

cspan span() const;
cspan span(uint32_t start) const;
cspan span(uint32_t start, uint32_t endOffset) const;

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

size

uint32_t size() const;

operator[]

T& operator[](uint32_t i);
const T& operator[](uint32_t i) const;

Returns an element by zero-based index. An index outside the current size raises COutOfRangeError.

back

T& back();
const T& back() const;

Returns the final logical element. An empty vector raises COutOfRangeError.

data

T* data();
const T* data() const;

view

std::span<T> view();
std::span<const T> view() const;

Returns a borrowed span over the current elements. Keep the container alive and do not use the view after an operation that invalidates its storage.

find

iterator find(const T& x);

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

insert

iterator insert(uint32_t i, const T& x);
iterator insert(iterator itr, const T& x);

Inserts before an index or a compatible iterator, shifting later elements. Capacity overflow raises CLengthError; returns an iterator to the new element.

operator<<

CSVector& operator<<(const T& x);

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

push_back

void push_back(const T& x);

Adds an element after the current contents. Raises CLengthError if the fixed capacity is already full.

append

void append(const CSVector& v);

Copies all source elements after the current contents. Checks that the complete result fits N before appending.

erase

void erase(uint32_t i);

Removes an indexed element and shifts later elements left. An invalid index raises COutOfRangeError.

pop_back

void pop_back();

Reduces the logical size by one; an empty vector raises COutOfRangeError. The underlying element object remains in fixed storage.

popBack

T popBack();

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

clear

void clear();

Resets the logical size to zero. The fixed storage and its element objects remain alive until overwritten or the vector is destroyed.

CSVector::iterator

class iterator

Methods

operator++

iterator& operator++();
iterator operator++(int);

operator!=

bool operator!=(const iterator& itr) const;

operator==

bool operator==(const iterator& itr) const;

index

uint32_t index() const;

Returns the zero-based position stored by this iterator. This is also available for the end iterator, whose index equals the vector size.

CSVector::const_iterator

class const_iterator

Methods

operator++

const_iterator& operator++();
const_iterator operator++(int);

operator!=

bool operator!=(const const_iterator& itr) const;

operator==

bool operator==(const const_iterator& itr) const;

operator+

const_iterator operator+(uint32_t i) const;

operator-

const_iterator operator-(uint32_t i) const;

index

uint32_t index() const;

Returns the zero-based position stored by this iterator. This is also available for the end iterator, whose index equals the vector size.

Free functions & types

Functions

operator<<

template<class T, uint32_t N> inline std::ostream& operator<<(std::ostream& ostr, const CSVector<T, N>& v);