Stratax 0.2.0
Loading...
Searching...
No Matches
stratax::container::Vector< T > Class Template Reference

Stores a rank-1 Stratax array in contiguous memory. More...

#include <Vector.hpp>

Public Types

using value_type = T
 Element type stored by the vector.
using iterator = typename core::Buffer<T>::iterator
 Mutable iterator over vector elements.
using const_iterator = typename core::Buffer<T>::const_iterator
 Const iterator over vector elements.
using reverse_iterator = typename core::Buffer<T>::reverse_iterator
 Mutable reverse iterator over vector elements.
using const_reverse_iterator = typename core::Buffer<T>::const_reverse_iterator
 Const reverse iterator over vector elements.
template<typename U>
using rebind = Vector<U>
 Rebinds the vector container to another element type.

Public Member Functions

 Vector () noexcept=default
 Creates a default vector with no logical dimensions.
 Vector (std::size_t size)
 Creates a vector with the given number of elements.
 Vector (const core::Shape &shape)
 Creates a vector from a validated rank-1 shape.
 Vector (std::size_t size, const T &value)
 Creates a vector and fills it with a value.
 Vector (std::initializer_list< T > list)
 Creates a vector from an initializer list.
 Vector (const Vector &)=default
 Creates a copy of another vector.
 Vector (Vector &&) noexcept=default
 Transfers ownership from another vector.
Vectoroperator= (const Vector &)=default
 Replaces this vector with a copy of another vector.
Vectoroperator= (Vector &&) noexcept=default
 Replaces this vector by taking ownership from another vector.
 ~Vector ()=default
 Destroys the vector.
T & operator() (std::size_t index) noexcept
 Returns a flat element without bounds checking.
const T & operator() (std::size_t index) const noexcept
 Returns a flat element without bounds checking.
T & operator[] (std::size_t index) noexcept
 Returns a flat element without bounds checking.
const T & operator[] (std::size_t index) const noexcept
 Returns a flat element without bounds checking.
T & at (std::ptrdiff_t index)
 Returns a flat element with bounds checking.
const T & at (std::ptrdiff_t index) const
 Returns a flat element with bounds checking.
T & front ()
 Returns the first element.
const T & front () const
 Returns the first element as a const reference.
T & back ()
 Returns the last element.
const T & back () const
 Returns the last element as a const reference.
std::size_t size () const noexcept
 Returns the number of stored elements.
std::size_t rank () const noexcept
 Returns the vector rank.
bool empty () const noexcept
 Returns whether the vector has no elements.
const stratax::core::Shapeshape () const noexcept
 Returns the vector shape.
const stratax::core::Stridesstrides () const noexcept
 Returns the vector strides.
T * data () noexcept
 Returns the raw data pointer.
const T * data () const noexcept
 Returns the raw data pointer as a const pointer.
iterator begin () noexcept
 Returns an iterator to the first element.
const_iterator begin () const noexcept
 Returns a const iterator to the first element.
const_iterator cbegin () const noexcept
 Returns a const iterator to the first element.
iterator end () noexcept
 Returns an iterator one past the last element.
const_iterator end () const noexcept
 Returns a const iterator one past the last element.
const_iterator cend () const noexcept
 Returns a const iterator one past the last element.
reverse_iterator rbegin () noexcept
 Returns a reverse iterator to the last element.
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the last element.
const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the last element.
reverse_iterator rend () noexcept
 Returns a reverse iterator before the first element.
const_reverse_iterator rend () const noexcept
 Returns a const reverse iterator before the first element.
const_reverse_iterator crend () const noexcept
 Returns a const reverse iterator before the first element.
void fill (const T &value)
 Fills every element with the same value.
void swap (Vector &other) noexcept
 Swaps the contents of two vectors.

Detailed Description

template<typename T>
requires Numeric<T>
class stratax::container::Vector< T >

Stores a rank-1 Stratax array in contiguous memory.

Vector owns its element storage and pairs it with shape and stride metadata so the container can participate in the generic array API.

Template Parameters
TNumeric element type.

Definition at line 26 of file Vector.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T>
using stratax::container::Vector< T >::const_iterator = typename core::Buffer<T>::const_iterator

Const iterator over vector elements.

Definition at line 41 of file Vector.hpp.

◆ const_reverse_iterator

template<typename T>
using stratax::container::Vector< T >::const_reverse_iterator = typename core::Buffer<T>::const_reverse_iterator

Const reverse iterator over vector elements.

Definition at line 47 of file Vector.hpp.

◆ iterator

template<typename T>
using stratax::container::Vector< T >::iterator = typename core::Buffer<T>::iterator

Mutable iterator over vector elements.

Definition at line 38 of file Vector.hpp.

◆ rebind

template<typename T>
template<typename U>
using stratax::container::Vector< T >::rebind = Vector<U>

Rebinds the vector container to another element type.

Definition at line 51 of file Vector.hpp.

◆ reverse_iterator

template<typename T>
using stratax::container::Vector< T >::reverse_iterator = typename core::Buffer<T>::reverse_iterator

Mutable reverse iterator over vector elements.

Definition at line 44 of file Vector.hpp.

◆ value_type

template<typename T>
using stratax::container::Vector< T >::value_type = T

Element type stored by the vector.

Definition at line 35 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/5]

template<typename T>
stratax::container::Vector< T >::Vector ( )
defaultnoexcept

Creates a default vector with no logical dimensions.

The default vector has rank 0 and owns no element storage. Use Vector(0) when a rank-1 empty vector is required.

◆ Vector() [2/5]

template<typename T>
stratax::container::Vector< T >::Vector ( std::size_t size)
inlineexplicit

Creates a vector with the given number of elements.

Parameters
sizeNumber of elements to allocate.

Definition at line 68 of file Vector.hpp.

◆ Vector() [3/5]

template<typename T>
stratax::container::Vector< T >::Vector ( const core::Shape & shape)
inlineexplicit

Creates a vector from a validated rank-1 shape.

Parameters
shapeSource shape.
Exceptions
Exceptions::DimensionErrorIf the shape is not rank 1.

Definition at line 82 of file Vector.hpp.

◆ Vector() [4/5]

template<typename T>
stratax::container::Vector< T >::Vector ( std::size_t size,
const T & value )
inline

Creates a vector and fills it with a value.

Parameters
sizeNumber of elements to allocate.
valueValue to copy into each element.

Definition at line 96 of file Vector.hpp.

◆ Vector() [5/5]

template<typename T>
stratax::container::Vector< T >::Vector ( std::initializer_list< T > list)
inline

Creates a vector from an initializer list.

Parameters
listSource values in element order.

Definition at line 109 of file Vector.hpp.

Member Function Documentation

◆ at() [1/2]

template<typename T>
T & stratax::container::Vector< T >::at ( std::ptrdiff_t index)
inline

Returns a flat element with bounds checking.

Parameters
indexFlat element index.
Returns
Mutable reference to the indexed element.
Exceptions
Exceptions::IndexErrorIf the index is out of bounds.

Definition at line 209 of file Vector.hpp.

◆ at() [2/2]

template<typename T>
const T & stratax::container::Vector< T >::at ( std::ptrdiff_t index) const
inline

Returns a flat element with bounds checking.

Parameters
indexFlat element index.
Returns
Const reference to the indexed element.
Exceptions
Exceptions::IndexErrorIf the index is out of bounds.

Definition at line 225 of file Vector.hpp.

◆ back() [1/2]

template<typename T>
T & stratax::container::Vector< T >::back ( )
inline

Returns the last element.

Returns
Mutable reference to the last stored element.

Definition at line 257 of file Vector.hpp.

◆ back() [2/2]

template<typename T>
const T & stratax::container::Vector< T >::back ( ) const
inline

Returns the last element as a const reference.

Returns
Const reference to the last stored element.

Definition at line 267 of file Vector.hpp.

◆ begin() [1/2]

template<typename T>
const_iterator stratax::container::Vector< T >::begin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first element.

Returns
Const iterator to the beginning of the vector.

Definition at line 357 of file Vector.hpp.

◆ begin() [2/2]

template<typename T>
iterator stratax::container::Vector< T >::begin ( )
inlinenodiscardnoexcept

Returns an iterator to the first element.

Returns
Iterator to the beginning of the vector.

Definition at line 347 of file Vector.hpp.

◆ cbegin()

template<typename T>
const_iterator stratax::container::Vector< T >::cbegin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first element.

Returns
Const iterator to the beginning of the vector.

Definition at line 367 of file Vector.hpp.

◆ cend()

template<typename T>
const_iterator stratax::container::Vector< T >::cend ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last element.

Returns
Const iterator to the end of the vector.

Definition at line 397 of file Vector.hpp.

◆ crbegin()

template<typename T>
const_reverse_iterator stratax::container::Vector< T >::crbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last element.

Returns
Const reverse iterator starting at the last element.

Definition at line 427 of file Vector.hpp.

◆ crend()

template<typename T>
const_reverse_iterator stratax::container::Vector< T >::crend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first element.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 457 of file Vector.hpp.

◆ data() [1/2]

template<typename T>
const T * stratax::container::Vector< T >::data ( ) const
inlinenodiscardnoexcept

Returns the raw data pointer as a const pointer.

Returns
Pointer to the first stored element, or nullptr when empty.

Definition at line 337 of file Vector.hpp.

◆ data() [2/2]

template<typename T>
T * stratax::container::Vector< T >::data ( )
inlinenodiscardnoexcept

Returns the raw data pointer.

Returns
Pointer to the first stored element, or nullptr when empty.

Definition at line 327 of file Vector.hpp.

◆ empty()

template<typename T>
bool stratax::container::Vector< T >::empty ( ) const
inlinenodiscardnoexcept

Returns whether the vector has no elements.

Returns
true when the vector size is zero.

Definition at line 297 of file Vector.hpp.

◆ end() [1/2]

template<typename T>
const_iterator stratax::container::Vector< T >::end ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last element.

Returns
Const iterator to the end of the vector.

Definition at line 387 of file Vector.hpp.

◆ end() [2/2]

template<typename T>
iterator stratax::container::Vector< T >::end ( )
inlinenodiscardnoexcept

Returns an iterator one past the last element.

Returns
Iterator to the end of the vector.

Definition at line 377 of file Vector.hpp.

◆ fill()

template<typename T>
void stratax::container::Vector< T >::fill ( const T & value)
inline

Fills every element with the same value.

Parameters
valueValue to assign to each element.

Definition at line 467 of file Vector.hpp.

◆ front() [1/2]

template<typename T>
T & stratax::container::Vector< T >::front ( )
inline

Returns the first element.

Returns
Mutable reference to the first stored element.

Definition at line 237 of file Vector.hpp.

◆ front() [2/2]

template<typename T>
const T & stratax::container::Vector< T >::front ( ) const
inline

Returns the first element as a const reference.

Returns
Const reference to the first stored element.

Definition at line 247 of file Vector.hpp.

◆ operator()() [1/2]

template<typename T>
const T & stratax::container::Vector< T >::operator() ( std::size_t index) const
inlinenoexcept

Returns a flat element without bounds checking.

Parameters
indexFlat element index.
Returns
Const reference to the indexed element.
Warning
The caller must ensure that the index is in range.

Definition at line 169 of file Vector.hpp.

◆ operator()() [2/2]

template<typename T>
T & stratax::container::Vector< T >::operator() ( std::size_t index)
inlinenoexcept

Returns a flat element without bounds checking.

Parameters
indexFlat element index.
Returns
Mutable reference to the indexed element.
Warning
The caller must ensure that the index is in range.

Definition at line 156 of file Vector.hpp.

◆ operator[]() [1/2]

template<typename T>
const T & stratax::container::Vector< T >::operator[] ( std::size_t index) const
inlinenoexcept

Returns a flat element without bounds checking.

Parameters
indexFlat element index.
Returns
Const reference to the indexed element.
Warning
The caller must ensure that the index is in range.

Definition at line 195 of file Vector.hpp.

◆ operator[]() [2/2]

template<typename T>
T & stratax::container::Vector< T >::operator[] ( std::size_t index)
inlinenoexcept

Returns a flat element without bounds checking.

Parameters
indexFlat element index.
Returns
Mutable reference to the indexed element.
Warning
The caller must ensure that the index is in range.

Definition at line 182 of file Vector.hpp.

◆ rank()

template<typename T>
std::size_t stratax::container::Vector< T >::rank ( ) const
inlinenodiscardnoexcept

Returns the vector rank.

Returns
The number of dimensions, normally 1 for constructed vectors and 0 for the default state.

Definition at line 287 of file Vector.hpp.

◆ rbegin() [1/2]

template<typename T>
const_reverse_iterator stratax::container::Vector< T >::rbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last element.

Returns
Const reverse iterator starting at the last element.

Definition at line 417 of file Vector.hpp.

◆ rbegin() [2/2]

template<typename T>
reverse_iterator stratax::container::Vector< T >::rbegin ( )
inlinenodiscardnoexcept

Returns a reverse iterator to the last element.

Returns
Reverse iterator starting at the last element.

Definition at line 407 of file Vector.hpp.

◆ rend() [1/2]

template<typename T>
const_reverse_iterator stratax::container::Vector< T >::rend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first element.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 447 of file Vector.hpp.

◆ rend() [2/2]

template<typename T>
reverse_iterator stratax::container::Vector< T >::rend ( )
inlinenodiscardnoexcept

Returns a reverse iterator before the first element.

Returns
Reverse iterator representing the end sentinel.

Definition at line 437 of file Vector.hpp.

◆ shape()

template<typename T>
const stratax::core::Shape & stratax::container::Vector< T >::shape ( ) const
inlinenoexcept

Returns the vector shape.

Returns
Shape describing the vector.

Definition at line 307 of file Vector.hpp.

◆ size()

template<typename T>
std::size_t stratax::container::Vector< T >::size ( ) const
inlinenodiscardnoexcept

Returns the number of stored elements.

Returns
Number of elements in the vector.

Definition at line 277 of file Vector.hpp.

◆ strides()

template<typename T>
const stratax::core::Strides & stratax::container::Vector< T >::strides ( ) const
inlinenoexcept

Returns the vector strides.

Returns
Strides describing the vector.

Definition at line 317 of file Vector.hpp.

◆ swap()

template<typename T>
void stratax::container::Vector< T >::swap ( Vector< T > & other)
inlinenoexcept

Swaps the contents of two vectors.

Parameters
otherVector to exchange state with.

Definition at line 477 of file Vector.hpp.


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