template<CopyMove Type, typename VectorType VectorType = std::vector<Type>, typename IndexType IndexType = ElementIndex<Type>>
gtopt::Collection class

A container for managing typed elements with efficient lookup by name, UID, or index.

Template parameters
Type The element type stored in the collection (must satisfy CopyMove concept)
VectorType The container type used for storage (defaults to std::vector)
IndexType The strongly-typed index used for safe element access

The Collection class provides a central repository for elements of a specific type, with optimized access through multiple lookup methods. It enforces unique UIDs and names across all contained elements.

Constructors, destructors, conversion operators

Collection() defaulted
Collection(Collection&&) defaulted noexcept
Collection(const Collection&) defaulted
Collection(vector_t pelements) explicit
~Collection() defaulted

Public functions

auto build_maps() -> void
template<typename Self Self, typename ID ID>
auto element(this Self&& self, const ID& id) -> constexpr auto&&
Get a reference to an element by its ID.
template<typename ID ID>
auto element_index(const ID& id) const -> constexpr auto noexcept(…)
Get the index of an element by its ID (name, UID, or compound ID)
template<typename Self Self>
auto elements(this Self&& self) -> constexpr auto&& noexcept
Get a reference to the underlying element vector (mutable version)
auto empty() const -> constexpr auto noexcept
auto operator=(Collection&&) -> Collection& defaulted noexcept
auto operator=(const Collection&) -> Collection& defaulted
template<typename EType EType>
auto push_back(EType&& element) -> auto
auto size() const -> constexpr auto noexcept
Get the number of elements in the collection.

Function documentation

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType>
gtopt::Collection<Type, VectorType, IndexType>::Collection(Collection&&) defaulted noexcept

Special member functions with explicit noexcept specifications to enable move plannings and provide strong exception-safety guarantees.

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType>
gtopt::Collection<Type, VectorType, IndexType>::Collection(vector_t pelements) explicit

Parameters
pelements Vector containing the elements to store

Constructor that takes ownership of an existing vector. Uses move semantics to avoid copying the elements.

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType>
void gtopt::Collection<Type, VectorType, IndexType>::build_maps()

Builds the mapping structures for efficient element lookup by name or UID. Uses move semantics to efficiently transfer ownership from temporary maps to member maps once they're fully constructed.

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType> template<typename Self Self, typename ID ID>
constexpr auto&& gtopt::Collection<Type, VectorType, IndexType>::element(this Self&& self, const ID& id)

Get a reference to an element by its ID.

Parameters
self The collection object (deduced; supports const and non-const).
id The identifier to lookup
Returns A reference to the requested element
Exceptions
std::out_of_range if the element is not found

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType> template<typename ID ID>
constexpr auto gtopt::Collection<Type, VectorType, IndexType>::element_index(const ID& id) const noexcept(…)

Get the index of an element by its ID (name, UID, or compound ID)

Parameters
id The identifier to lookup
Returns A strongly-typed index to the element
Exceptions
std::out_of_range if the element is not found

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType> template<typename Self Self>
constexpr auto&& gtopt::Collection<Type, VectorType, IndexType>::elements(this Self&& self) noexcept

Get a reference to the underlying element vector (mutable version)

Returns A mutable reference to the element vector

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType> template<typename EType EType>
auto gtopt::Collection<Type, VectorType, IndexType>::push_back(EType&& element)

Parameters
element The element to add (can be lvalue or rvalue)
Returns The index of the newly added element

Adds an element to the collection using perfect forwarding. The template parameter allows both lvalue and rvalue references to be passed efficiently without unnecessary copies.

template<CopyMove Type, typename VectorType VectorType, typename IndexType IndexType>
constexpr auto gtopt::Collection<Type, VectorType, IndexType>::size() const noexcept

Get the number of elements in the collection.

Returns The element count