MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
cda_rail::FixedSizeVector< T > Class Template Reference

A heap-allocated, fixed-size array whose capacity cannot change after construction. More...

#include <FixedSizeVector.hpp>

Public Member Functions

 FixedSizeVector ()=default
 Constructs an empty vector with zero elements.
 FixedSizeVector (size_t const len)
 Constructs a vector with len default-initialized elements.
 FixedSizeVector (std::initializer_list< T > init)
 Constructs a fixed size vector with given values.
 FixedSizeVector (const FixedSizeVector &other)
 Creates a deep copy of another vector's elements.
FixedSizeVector & operator= (const FixedSizeVector &other)
 Assigns a copy of another vector to this vector.
 FixedSizeVector (FixedSizeVector &&other) noexcept
 Transfers ownership of the managed array from another vector.
FixedSizeVector & operator= (FixedSizeVector &&other) noexcept
 Move-assigns from another FixedSizeVector.
 ~FixedSizeVector ()=default
 Destructor. Releases the managed array.
void swap (FixedSizeVector &other) noexcept
 Swaps the contents of this vector with other.
void delete_and_resize (size_t const len)
 Replaces the storage with a new allocation of len elements.
T & operator[] (size_t const i)
 Unchecked element access (non-const).
const T & operator[] (size_t const i) const
 Accesses an element at a specific index without bounds checking.
T & at (size_t const i)
 Accesses an element at a given index with bounds checking.
const T & at (size_t const i) const
 Bounds-checked element access (const).
T * begin ()
 Accesses the first element of the underlying array.
T * end ()
 Provides a pointer to the position past the last element.
const T * begin () const
 Obtains a const pointer to the first element.
const T * end () const
 Obtains a const pointer to one past the last element.
const T * cbegin () const
 Obtains a const pointer to the first element.
const T * cend () const
 Provides a const pointer to one past the last element.
size_t size () const
 Queries the number of elements.

Detailed Description

template<typename T>
class cda_rail::FixedSizeVector< T >

A heap-allocated, fixed-size array whose capacity cannot change after construction.

Provides a lightweight alternative to std::vector<T> for situations where the number of elements is determined at run time but remains constant for the lifetime of the object. The storage is managed through a std::unique_ptr<T[]>, giving deterministic ownership without the capacity overhead of std::vector.

Template Parameters
TElement type. Must be default-constructible because the underlying array is zero-initialized on construction.
Invariant
All indices in [0, size()) refer to valid, initialized elements.

Constructor & Destructor Documentation

◆ FixedSizeVector() [1/5]

template<typename T>
cda_rail::FixedSizeVector< T >::FixedSizeVector ( )
default

Constructs an empty vector with zero elements.

◆ FixedSizeVector() [2/5]

template<typename T>
cda_rail::FixedSizeVector< T >::FixedSizeVector ( size_t const len)
inlineexplicit

Constructs a vector with len default-initialized elements.

Parameters
lenNumber of elements to allocate.

◆ FixedSizeVector() [3/5]

template<typename T>
cda_rail::FixedSizeVector< T >::FixedSizeVector ( std::initializer_list< T > init)
inline

Constructs a fixed size vector with given values.

Parameters
initValues to store in a fixed vector

◆ FixedSizeVector() [4/5]

template<typename T>
cda_rail::FixedSizeVector< T >::FixedSizeVector ( const FixedSizeVector< T > & other)
inline

Creates a deep copy of another vector's elements.

Parameters
otherSource vector to copy from.

◆ FixedSizeVector() [5/5]

template<typename T>
cda_rail::FixedSizeVector< T >::FixedSizeVector ( FixedSizeVector< T > && other)
inlinenoexcept

Transfers ownership of the managed array from another vector.

After the move, other is in a valid but unspecified state.

◆ ~FixedSizeVector()

template<typename T>
cda_rail::FixedSizeVector< T >::~FixedSizeVector ( )
default

Destructor. Releases the managed array.

Member Function Documentation

◆ at() [1/2]

template<typename T>
T & cda_rail::FixedSizeVector< T >::at ( size_t const i)
inlinenodiscard

Accesses an element at a given index with bounds checking.

Parameters
iZero-based index of the element.
Returns
Reference to the element at position i.
Exceptions
std::out_of_rangeIf i >= size().

◆ at() [2/2]

template<typename T>
const T & cda_rail::FixedSizeVector< T >::at ( size_t const i) const
inlinenodiscard

Bounds-checked element access (const).

Parameters
iZero-based index of the element.
Returns
Const reference to the element at position i.
Exceptions
std::out_of_rangeIf i >= size().

◆ begin() [1/2]

template<typename T>
T * cda_rail::FixedSizeVector< T >::begin ( )
inlinenodiscard

Accesses the first element of the underlying array.

Returns
Pointer to the first element.

◆ begin() [2/2]

template<typename T>
const T * cda_rail::FixedSizeVector< T >::begin ( ) const
inlinenodiscard

Obtains a const pointer to the first element.

Returns
Const pointer to the first element, or a pointer equal to cend() if empty.

◆ cbegin()

template<typename T>
const T * cda_rail::FixedSizeVector< T >::cbegin ( ) const
inlinenodiscard

Obtains a const pointer to the first element.

Returns
Const pointer to the first element.

◆ cend()

template<typename T>
const T * cda_rail::FixedSizeVector< T >::cend ( ) const
inlinenodiscard

Provides a const pointer to one past the last element.

Returns
const T* A const pointer to one past the last element.

◆ delete_and_resize()

template<typename T>
void cda_rail::FixedSizeVector< T >::delete_and_resize ( size_t const len)
inline

Replaces the storage with a new allocation of len elements.

All existing elements are discarded and the new elements are default-initialized.

Parameters
lenNew number of elements.

◆ end() [1/2]

template<typename T>
T * cda_rail::FixedSizeVector< T >::end ( )
inlinenodiscard

Provides a pointer to the position past the last element.

Returns
Pointer to one past the last element.

◆ end() [2/2]

template<typename T>
const T * cda_rail::FixedSizeVector< T >::end ( ) const
inlinenodiscard

Obtains a const pointer to one past the last element.

Returns
A const pointer one past the last element.

◆ operator=() [1/2]

template<typename T>
FixedSizeVector & cda_rail::FixedSizeVector< T >::operator= ( const FixedSizeVector< T > & other)
inline

Assigns a copy of another vector to this vector.

Parameters
otherSource vector to copy from.
Returns
Reference to this vector.

◆ operator=() [2/2]

template<typename T>
FixedSizeVector & cda_rail::FixedSizeVector< T >::operator= ( FixedSizeVector< T > && other)
inlinenoexcept

Move-assigns from another FixedSizeVector.

After the move, the source object is in a valid but unspecified state.

Returns
Reference to this object.

◆ operator[]() [1/2]

template<typename T>
T & cda_rail::FixedSizeVector< T >::operator[] ( size_t const i)
inlinenodiscard

Unchecked element access (non-const).

Parameters
iZero-based index of the element.
Returns
Reference to the element at position i.
Precondition
i < size(). Behavior is undefined if the precondition is violated.

◆ operator[]() [2/2]

template<typename T>
const T & cda_rail::FixedSizeVector< T >::operator[] ( size_t const i) const
inlinenodiscard

Accesses an element at a specific index without bounds checking.

Returns
Const reference to the element at position i.
Precondition
i < size(). Behavior is undefined if the precondition is violated.

◆ size()

template<typename T>
size_t cda_rail::FixedSizeVector< T >::size ( ) const
inlinenodiscard

Queries the number of elements.

Returns
The number of elements in the vector (fixed after construction until delete_and_resize is called).

◆ swap()

template<typename T>
void cda_rail::FixedSizeVector< T >::swap ( FixedSizeVector< T > & other)
inlinenoexcept

Swaps the contents of this vector with other.

Parameters
otherVector to swap with.

The documentation for this class was generated from the following file: