A growable contiguous sequence with standard vector operations and concise additions.
CVector
template<class T, class Alloc = std::allocator<T>> class CVector
Types, constants & data
using Vector = std::vector<T, Alloc>;
using iterator = typename Vector::iterator;
using const_iterator = typename Vector::const_iterator;
using reverse_iterator = typename Vector::reverse_iterator;
using const_reverse_iterator = typename Vector::const_reverse_iterator;
using reference = typename Vector::reference;
using const_reference = typename Vector::const_reference;
using allocator_type = typename Vector::allocator_type;
using pointer = typename Vector::pointer;
using const_pointer = typename Vector::const_pointer;
using size_type = typename Vector::size_type;
using difference_type = typename Vector::difference_type;
using indexed_type = reference;
Methods
constexpr CVector() noexcept(noexcept(Alloc()));
constexpr explicit CVector(const Alloc& alloc) noexcept;
constexpr explicit CVector(size_type n, const Alloc& alloc = cContainerDefault<Alloc>());
constexpr CVector(size_type n, const T& value, const Alloc& alloc = cContainerDefault<Alloc>());
template<CInputIterator I> constexpr CVector(I first, I last, const Alloc& alloc = cContainerDefault<Alloc>());
template<CContainerRange<T> R> constexpr CVector(std::from_range_t, R&& range, const Alloc& alloc = cContainerDefault<Alloc>());
constexpr CVector(const CVector& x);
constexpr CVector(CVector&& x) noexcept;
constexpr CVector(const CVector& x, const std::type_identity_t<Alloc>& alloc);
constexpr CVector(CVector&& x, const std::type_identity_t<Alloc>& alloc);
constexpr CVector(const Vector& x);
constexpr CVector(Vector&& x) noexcept;
constexpr CVector(const Vector& x, const std::type_identity_t<Alloc>& alloc);
constexpr CVector(Vector&& x, const std::type_identity_t<Alloc>& alloc);
constexpr CVector(std::initializer_list<value_type> il, const Alloc& alloc = cContainerDefault<Alloc>());
CVector(CBuffer& b);
CVector(std::function<CVector()> f);
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.
template<class... Args> static CVector 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.
template<class... Ts> void fromTuple(const std::tuple<Ts...>& t);
Appends each tuple field in order, converting fields to the vector element type. Existing vector elements are retained.
static CVector range(int64_t a, int64_t b);
static CVector 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).
constexpr CVector& operator=(const CVector& x);
constexpr CVector& operator=(CVector&& x) noexcept(noexcept(v_ = std::move(x.v_)));
constexpr CVector& operator=(std::initializer_list<value_type> il);
template<CInputIterator InputIterator> constexpr void assign(InputIterator first, InputIterator last);
constexpr void assign(size_type n, const T& u);
constexpr 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.
Replaces the contents with the elements of a C++ range. Each range element must be convertible to the container element type.
constexpr iterator begin() noexcept;
constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr iterator end() noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
constexpr reverse_iterator rbegin() noexcept;
constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
constexpr reverse_iterator rend() noexcept;
constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
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.
constexpr bool empty() const noexcept;
constexpr size_type size() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr size_type capacity() const noexcept;
constexpr void reserve(size_type n);
Ensures capacity for at least the requested element count without changing size(). Reallocation invalidates pointers, references, and iterators into the storage.
constexpr void shrink_to_fit() noexcept(noexcept(v_.shrink_to_fit()));
Requests release of unused capacity. The underlying container may retain capacity, and storage relocation can invalidate existing references and iterators.
constexpr reference operator[](size_type n);
constexpr const_reference operator[](size_type n) const;
Returns the element at a zero-based index. The index must be below size(); this is not a checked, recoverable out-of-range lookup.
constexpr const_reference at(size_type n) const;
constexpr reference at(size_type n);
Returns the element at a zero-based index. An invalid index raises COutOfRangeError.
const_reference uget(size_t n, const T& def) const;
Returns the indexed element, or def when the index is outside the container. The reference overload borrows either the element or the supplied fallback; it does not extend either lifetime.
constexpr reference front() noexcept(noexcept(v_.front()));
constexpr const_reference front() const noexcept(noexcept(v_.front()));
Returns the first element by reference. The container must be nonempty.
constexpr reference back() noexcept(noexcept(v_.back()));
constexpr const_reference back() const noexcept(noexcept(v_.back()));
constexpr reference back(size_t i);
constexpr const_reference back(size_t i) const;
Returns the last element, or the element i positions before it: back(0) is the last element. The container must contain the requested element.
constexpr value_type* data() noexcept requires(!std::same_as<T, bool>);
constexpr const value_type* data() const noexcept requires(!std::same_as<T, bool>);
std::span<T> view() noexcept requires(!CSame<T, bool>);
std::span<const T> view() const noexcept requires(!CSame<T, bool>);
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.
iterator find(const T& v);
const_iterator find(const T& v) const;
Returns an iterator to the first equal element, or end() when absent. The search is linear.
size_t indexOf(const T& v) const;
Returns the matching index, or size() if no element matches.
bool hasIndex(size_t i) const;
Tests whether the index is below size(), without accessing or adding an element.
bool has(const T& v) const;
Reports whether an equal element occurs in the container.
constexpr iterator insert(size_t index, const T& x);
constexpr iterator insert(size_t index, T&& x);
constexpr iterator insert(const_iterator position, const T& x);
constexpr iterator insert(const_iterator position, T&& x);
constexpr iterator insert(const_iterator position, size_type n, const T& x);
template<CInputIterator InputIterator> constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last);
constexpr iterator insert(const_iterator position, std::initializer_list<T> values);
Inserts before a valid position or index; an index equal to size() appends. Returns the iterator to the inserted element or the first element of an inserted range.
template<CContainerRange<T> R> constexpr 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.
template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
Constructs an element before the given position from forwarded constructor arguments. Returns its iterator.
void put(size_t i, const T& v);
void put(size_t i, T&& v);
Assigns an element by index, first growing the container to i + 1 when necessary. Any intervening new elements are value-initialized.
template<class V> CVector& operator<<(V&& x);
Appends one element and returns this container, allowing chained appends.
constexpr void push_back(const T& x);
constexpr void push_back(T&& x);
template<class... Args> constexpr reference emplace_back(Args&&... args);
Constructs an element at the end from forwarded constructor arguments and returns a reference to it.
template<CItems S> void append(const S& items);
void append(const CVector& v);
void append(CVector&& v);
Appends elements after the existing contents. The rvalue-vector overload moves individual elements but retains the source vector’s size; its elements are left moved from.
Adds a C++ range at the end, preserving the order of its elements. Existing contents remain at the beginning.
void pushFront(const T& x);
void pushFront(T&& x);
Inserts one value at the beginning, shifting existing elements. References at or after that position are invalidated.
constexpr iterator erase(const_iterator position);
constexpr iterator erase(const_iterator first, const_iterator last);
constexpr iterator erase(size_t index);
Removes the indexed element, the element at an iterator, or the half-open iterator range. Returns the iterator following the removed elements; indices and iterators must identify valid positions.
constexpr void pop_back() noexcept(noexcept(v_.back()));
Removes the last element without returning it. The container must be nonempty; use popBack() to retain its value.
Removes and returns the last element. The container must be nonempty.
void pop_front() noexcept(noexcept(v_.front()));
Removes the first element without returning it. The container must be nonempty; use popFront() to retain its value.
Removes and returns the first element. The container must be nonempty.
constexpr void clear() noexcept;
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.
constexpr void resize(size_type n) requires(!std::same_as<T, bool>);
constexpr void resize(size_type n, const T& value) requires(!std::same_as<T, bool>);
constexpr void resize(size_type n, bool value = false) requires(std::same_as<T, bool>);
Changes the number of elements, removing trailing elements or appending default/value-initialized elements. It changes size(), unlike reserve().
constexpr void swap(CVector& vec) noexcept(noexcept(v_.swap(vec.v_)));
static constexpr void swap(reference first, reference second) noexcept requires(std::same_as<T, bool>);
Reverses the current elements in place without changing size.
constexpr void flip() noexcept requires(std::same_as<T, bool>);
Inverts every stored bit in a CVector<bool> without changing its size.
Adds corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Updates this vector in place.
Adds corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Returns a new vector.
Subtracts corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Updates this vector in place.
Subtracts corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Returns a new vector.
Multiplies corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Updates this vector in place.
Multiplies corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Returns a new vector.
Divides corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Supply valid nonzero divisors for integral components. Updates this vector in place.
Divides corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Supply valid nonzero divisors for integral components. Returns a new vector.
Takes the remainder of corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Element types must support %; floating-point member remainder is not implemented. Supply valid nonzero divisors for integral components. Updates this vector in place.
Takes the remainder of corresponding components, or applies the scalar to every component. Vector operands must have compatible sizes; no size check is performed. Element types must support %; floating-point member remainder is not implemented. Supply valid nonzero divisors for integral components. Returns a new vector.
constexpr const Vector& std() const noexcept;
constexpr Vector& std() noexcept;
Returns a reference to the underlying standard container. Mutations affect this object directly; calls through that reference bypass Catalyst exception translation.
constexpr allocator_type get_allocator() const noexcept;
Appends the container to a CBuffer; restore it with the buffer-taking constructor.
void output(std::ostream& ostr) const;
Writes comma-separated elements to the stream without the surrounding container brackets.
Returns the stream-formatted representation as a cstr; this is display text rather than the binary storage format.