A sorted unique sequence with vector-style indexing and set operations.
Exceptions escaping container operations are translated to CError. Direct iterator operations, element references, and calls through .std() follow the underlying type’s contracts.
insert(value) returns an iterator/bool pair; a duplicate returns {end(), false}. Preserve sorted order and uniqueness when using the mutable element references or storage accessors.
CVectorSet
template<typename T, class Allocator = std::allocator<T>> class CVectorSet
Types, constants & data
using Vector = CVector<T, Allocator>;
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 indexed_type = reference;
Methods
Creates sorted unique storage. Initializer-list construction inserts and deduplicates values, but iterator-range construction copies the sequence directly: that range must already be sorted and unique. Buffer construction restores the stored sequence.
Builds the consecutive values in [a, b), or [0, size). An empty interval produces an empty set.
iterator begin() noexcept;
const_iterator begin() const noexcept;
const_iterator cbegin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
const_iterator cend() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator crbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
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 numeric indices from zero to size(), optionally excluding an initial or trailing portion. It does not return key/value pairs or an element view.
bool empty() const noexcept;
size_t size() const noexcept;
size_t max_size() const noexcept;
size_t capacity() const noexcept;
Ensures vector capacity without changing the element count. Reallocation invalidates existing element references and iterators.
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.
reference operator[](size_t n);
const_reference operator[](size_t n) const;
Returns an element by zero-based position. The position must be valid; mutations through the returned reference must preserve sorted order and uniqueness.
const_reference at(size_t n) const;
reference at(size_t n);
Returns the element at a zero-based index. An invalid index raises COutOfRangeError.
const T& 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.
reference front();
const_reference front() const;
Returns the first element by reference. The container must be nonempty.
reference back();
const_reference back() const;
reference back(size_t i);
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.
value_type* data() noexcept requires(!CSame<T, bool>);
const value_type* data() const noexcept requires(!CSame<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.
const Vector& vec() const;
Vector& vec();
Returns the underlying vector by reference. Any mutation must preserve the sorted, unique invariant expected by lookup and set operations.
iterator find(const T& x);
const_iterator find(const T& x) const;
Uses binary search to locate an equal value, returning end() when absent. The stored sequence must remain sorted.
bool has(const T& x) const;
Reports whether an equivalent key or element is present, without inserting anything.
std::pair<iterator, bool> insert(const T& x);
Inserts while preserving sorted uniqueness and returns the inserted position with true. An existing value returns {end(), false}, rather than an iterator to that existing element.
Inserts through push() and returns this set for chaining. Values remain sorted and unique.
Inserts a value in sorted order if it is not already present.
Appends raw elements without sorting or removing duplicates. Use only when all appended values follow the existing values in sorted, unique order; use unite() for a general union.
void orderedPush(const T& x);
Appends directly without checking order or duplicates. The new value must follow all existing elements in sorted, unique order.
iterator erase(iterator position);
void erase(const T& x);
Removes an element by iterator or by value. The iterator overload returns the following position; the value overload does nothing when absent. Later elements shift, invalidating references at and after the removal.
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.
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.
template<class S> void clearExcept(const S& s);
Removes entries whose keys are not present in s, as tested by s.has(key).
void resize(size_t size);
void resize(size_t size, const T& value);
Resizes the underlying vector. Growing it does not restore sorted order or uniqueness; callers must establish valid values before performing set operations.
void swap(CVectorSet& vec) noexcept(noexcept(v_.swap(vec.v_)));
Replaces this set with the elements shared by both sets. The supplied set is unchanged.
Reports whether the sets share any element. The implementation forms an intersection and may allocate temporary storage.
Adds the other set’s elements to this set, retaining each distinct value once. The supplied set is unchanged.
Removes from this set every element present in the supplied set. This is the directional difference: this set minus the argument.
template<class R> CVectorSet split(R& rng, size_t m);
Randomly retains m selected elements in this set and returns the remaining elements. Sets with fewer than two elements are left unchanged and return an empty set; the random generator determines sampling behavior.
Returns the intersection as a new set; both operands remain unchanged.
Returns the union as a new set; both operands remain unchanged.
Removes all elements found in the argument and returns this set.
Returns elements of this set that are absent from the argument, leaving both operands unchanged.
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 contents as a cstr. Use store() for binary serialization.