Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
stratax::container::Vector< T > Class Template Reference

#include <Vector.hpp>

Public Types

using value_type = T
template<typename U>
using rebind = Vector<U>

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::size_t index)
 Returns a flat element with bounds checking.
const T & at (std::size_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.
T * begin () noexcept
 Returns an iterator to the first element.
const T * begin () const noexcept
 Returns a const iterator to the first element.
const T * cbegin () const noexcept
 Returns a const iterator to the first element.
T * end () noexcept
 Returns an iterator one past the last element.
const T * end () const noexcept
 Returns a const iterator one past the last element.
const T * cend () const noexcept
 Returns a const iterator one past the last element.
std::reverse_iterator< T * > rbegin () noexcept
 Returns a reverse iterator to the last element.
std::reverse_iterator< const T * > rbegin () const noexcept
 Returns a const reverse iterator to the last element.
std::reverse_iterator< const T * > crbegin () const noexcept
 Returns a const reverse iterator to the last element.
std::reverse_iterator< T * > rend () noexcept
 Returns a reverse iterator before the first element.
std::reverse_iterator< const T * > rend () const noexcept
 Returns a const reverse iterator before the first element.
std::reverse_iterator< const T * > 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 >

Definition at line 26 of file Vector.hpp.

Member Typedef Documentation

◆ rebind

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

Definition at line 37 of file Vector.hpp.

◆ value_type

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

Definition at line 34 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/7]

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/7]

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 54 of file Vector.hpp.

◆ Vector() [3/7]

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 68 of file Vector.hpp.

◆ Vector() [4/7]

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 82 of file Vector.hpp.

◆ Vector() [5/7]

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 95 of file Vector.hpp.

◆ Vector() [6/7]

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

Creates a copy of another vector.

◆ Vector() [7/7]

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

Transfers ownership from another vector.

◆ ~Vector()

template<typename T>
stratax::container::Vector< T >::~Vector ( )
default

Destroys the vector.

Member Function Documentation

◆ at() [1/2]

template<typename T>
T & stratax::container::Vector< T >::at ( std::size_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 195 of file Vector.hpp.

◆ at() [2/2]

template<typename T>
const T & stratax::container::Vector< T >::at ( std::size_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 210 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 241 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 251 of file Vector.hpp.

◆ begin() [1/2]

template<typename T>
const T * 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 341 of file Vector.hpp.

◆ begin() [2/2]

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

Returns an iterator to the first element.

Returns
Iterator to the beginning of the vector.

Definition at line 331 of file Vector.hpp.

Referenced by stratax::container::operator<<().

◆ cbegin()

template<typename T>
const T * 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 351 of file Vector.hpp.

◆ cend()

template<typename T>
const T * 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 381 of file Vector.hpp.

◆ crbegin()

template<typename T>
std::reverse_iterator< const T * > 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 411 of file Vector.hpp.

◆ crend()

template<typename T>
std::reverse_iterator< const T * > 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 441 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 321 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 311 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 281 of file Vector.hpp.

◆ end() [1/2]

template<typename T>
const T * 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 371 of file Vector.hpp.

◆ end() [2/2]

template<typename T>
T * 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 361 of file Vector.hpp.

Referenced by stratax::container::operator<<().

◆ 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 451 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 221 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 231 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 155 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 142 of file Vector.hpp.

◆ operator=() [1/2]

template<typename T>
Vector & stratax::container::Vector< T >::operator= ( const Vector< T > & )
default

Replaces this vector with a copy of another vector.

◆ operator=() [2/2]

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

Replaces this vector by taking ownership from another vector.

◆ 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 181 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 168 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 271 of file Vector.hpp.

◆ rbegin() [1/2]

template<typename T>
std::reverse_iterator< const T * > 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 401 of file Vector.hpp.

◆ rbegin() [2/2]

template<typename T>
std::reverse_iterator< T * > 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 391 of file Vector.hpp.

◆ rend() [1/2]

template<typename T>
std::reverse_iterator< const T * > 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 431 of file Vector.hpp.

◆ rend() [2/2]

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

Returns a reverse iterator before the first element.

Returns
Reverse iterator representing the end sentinel.

Definition at line 421 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 291 of file Vector.hpp.

Referenced by astype().

◆ 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 261 of file Vector.hpp.

Referenced by astype(), stratax::container::Vector< U >::at(), stratax::container::Vector< U >::at(), and slice().

◆ 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 301 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 461 of file Vector.hpp.

Referenced by stratax::container::Vector< U >::swap().


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