Stratax 0.4.0rc1
Loading...
Searching...
No Matches
stratax::core::ArrayView< T > Class Template Reference

Non-owning view of elements with unsigned element strides. More...

#include <ArrayView.hpp>

Classes

class  basic_iterator
 Random-access iterator over logical flat indices of a view. More...
 

Public Types

using element_type = T
 Element type including any const qualifier.
 
using value_type = std::remove_const_t< element_type >
 Unqualified element type.
 
using size_type = std::size_t
 Unsigned extent and offset type.
 
using difference_type = std::ptrdiff_t
 Signed index and iterator-distance type.
 
using reference = element_type &
 Element reference, mutable only when T is mutable.
 
using const_reference = const value_type &
 Read-only element reference.
 
using pointer = element_type *
 Element pointer with the constness of T.
 
using const_pointer = const value_type *
 Read-only element pointer.
 
using const_view = ArrayView< const value_type >
 View type exposing read-only elements.
 
using iterator = basic_iterator< false >
 Mutable-view random-access iterator in logical order.
 
using const_iterator = basic_iterator< true >
 Read-only random-access iterator in logical order.
 

Public Member Functions

 ArrayView (pointer data, const Shape &shape, const Shape &strides)
 Constructs a view after validating shape and stride metadata.
 
template<typename U >
requires ( std::is_const_v<element_type> && !std::is_const_v<U> && std::same_as<value_type, std::remove_const_t<U>> )
 ArrayView (const ArrayView< U > &other)
 Creates a read-only alias of a mutable view, copying its metadata.
 
const Shape & shape () const noexcept
 Logical extents.
 
const Shape & strides () const noexcept
 Stored element strides.
 
size_type ndim () const noexcept
 Alias for rank().
 
size_type rank () const noexcept
 Number of logical axes.
 
size_type size () const noexcept
 Number of logical elements, zero for rank zero.
 
bool empty () const noexcept
 Whether there are no logical elements.
 
pointer data () noexcept
 Base storage pointer; empty views may have non-null pointers.
 
const_pointer data () const noexcept
 Read-only base pointer; empty views may have non-null pointers.
 
const_view as_const () const
 Read-only alias with copied metadata.
 
reference operator[] (size_type index)
 Unchecked logical flat access.
 
const_reference operator[] (size_type index) const
 Unchecked logical flat access.
 
iterator begin () noexcept
 First logical-element iterator.
 
const_iterator begin () const noexcept
 First logical-element iterator.
 
const_iterator cbegin () const noexcept
 First logical-element iterator.
 
iterator end () noexcept
 Past-the-end iterator.
 
const_iterator end () const noexcept
 Past-the-end iterator.
 
const_iterator cend () const noexcept
 Past-the-end iterator.
 
template<typename... Rest>
requires ((std::is_integral_v<Rest>) && ...)
reference operator() (size_type first, Rest... rest)
 Accesses an element using multidimensional indices with rank checking only.
 
template<typename... Rest>
requires ((std::is_integral_v<Rest>) && ...)
const_reference operator() (size_type first, Rest... rest) const
 Accesses an element using multidimensional indices with rank checking only.
 
reference at (difference_type index)
 Checked logical flat access with negative indices.
 
const_reference at (difference_type index) const
 Checked logical flat access with negative indices.
 
reference at (const std::vector< difference_type > &indices)
 Checked multidimensional access with negative indices.
 
const_reference at (const std::vector< difference_type > &indices) const
 Checked multidimensional access with negative indices.
 

Detailed Description

template<typename T>
class stratax::core::ArrayView< T >

Non-owning view of elements with unsigned element strides.

The view copies shape/stride metadata but never owns or extends the lifetime of the referenced storage. Copies alias the same elements. The caller must keep that allocation alive and large enough for every reachable offset. Strides may describe transposes, gaps, or repeated elements (zero strides); negative strides are not representable. Flat access follows logical row-major order, not necessarily physical storage order.

Template Parameters
TElement type, optionally const; const elements prohibit writes.
Invariant
Shape and stride ranks agree and the element count is representable.
Nonempty views have non-null data and representable maximum offsets.
Note
Const access to the view returns const element references. Constness does not prevent another alias from modifying the underlying storage.

Definition at line 37 of file ArrayView.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using stratax::core::ArrayView< T >::const_iterator = basic_iterator<true>

Read-only random-access iterator in logical order.

Definition at line 169 of file ArrayView.hpp.

◆ const_pointer

template<typename T >
using stratax::core::ArrayView< T >::const_pointer = const value_type*

Read-only element pointer.

Definition at line 55 of file ArrayView.hpp.

◆ const_reference

template<typename T >
using stratax::core::ArrayView< T >::const_reference = const value_type&

Read-only element reference.

Definition at line 51 of file ArrayView.hpp.

◆ const_view

template<typename T >
using stratax::core::ArrayView< T >::const_view = ArrayView<const value_type>

View type exposing read-only elements.

Definition at line 57 of file ArrayView.hpp.

◆ difference_type

template<typename T >
using stratax::core::ArrayView< T >::difference_type = std::ptrdiff_t

Signed index and iterator-distance type.

Definition at line 47 of file ArrayView.hpp.

◆ element_type

template<typename T >
using stratax::core::ArrayView< T >::element_type = T

Element type including any const qualifier.

Definition at line 41 of file ArrayView.hpp.

◆ iterator

template<typename T >
using stratax::core::ArrayView< T >::iterator = basic_iterator<false>

Mutable-view random-access iterator in logical order.

Definition at line 167 of file ArrayView.hpp.

◆ pointer

template<typename T >
using stratax::core::ArrayView< T >::pointer = element_type*

Element pointer with the constness of T.

Definition at line 53 of file ArrayView.hpp.

◆ reference

template<typename T >
using stratax::core::ArrayView< T >::reference = element_type&

Element reference, mutable only when T is mutable.

Definition at line 49 of file ArrayView.hpp.

◆ size_type

template<typename T >
using stratax::core::ArrayView< T >::size_type = std::size_t

Unsigned extent and offset type.

Definition at line 45 of file ArrayView.hpp.

◆ value_type

template<typename T >
using stratax::core::ArrayView< T >::value_type = std::remove_const_t<element_type>

Unqualified element type.

Definition at line 43 of file ArrayView.hpp.

Constructor & Destructor Documentation

◆ ArrayView() [1/2]

template<typename T >
stratax::core::ArrayView< T >::ArrayView ( pointer  data,
const Shape &  shape,
const Shape &  strides 
)
inline

Constructs a view after validating shape and stride metadata.

Parameters
dataBase address; may be null only for an empty view.
shapeLogical extents; rank zero describes an empty view.
stridesNon-negative strides measured in elements, one per axis.
Precondition
The caller provides live storage covering every reachable element.
Exceptions
Exceptions::RankErrorIf shape and stride ranks differ.
Exceptions::ValueErrorIf nonempty storage has a null pointer.
Exceptions::DimensionErrorIf the element count or maximum offset overflows.
std::bad_allocIf metadata allocation fails.
Complexity
O(shape.rank()).

Definition at line 183 of file ArrayView.hpp.

◆ ArrayView() [2/2]

template<typename T >
template<typename U >
requires ( std::is_const_v<element_type> && !std::is_const_v<U> && std::same_as<value_type, std::remove_const_t<U>> )
stratax::core::ArrayView< T >::ArrayView ( const ArrayView< U > &  other)
inline

Creates a read-only alias of a mutable view, copying its metadata.

Parameters
otherSource view; its allocation lifetime is still managed externally.
Exceptions
std::bad_allocIf copying metadata fails.
Complexity
O(other.rank()).

Definition at line 222 of file ArrayView.hpp.

Member Function Documentation

◆ as_const()

template<typename T >
const_view stratax::core::ArrayView< T >::as_const ( ) const
inline

Read-only alias with copied metadata.

Exceptions
std::bad_allocIf allocation fails.
Complexity
O(rank()).

Definition at line 286 of file ArrayView.hpp.

◆ at() [1/4]

template<typename T >
reference stratax::core::ArrayView< T >::at ( const std::vector< difference_type > &  indices)
inline

Checked multidimensional access with negative indices.

Parameters
indicesOne signed component per axis.
Exceptions
Exceptions::RankErrorIf the component count differs from rank().
Exceptions::IndexErrorIf the view is empty or a component is out of bounds.
Complexity
O(rank()).

Definition at line 397 of file ArrayView.hpp.

◆ at() [2/4]

template<typename T >
const_reference stratax::core::ArrayView< T >::at ( const std::vector< difference_type > &  indices) const
inline

Checked multidimensional access with negative indices.

Parameters
indicesOne signed component per axis.
Exceptions
Exceptions::RankErrorIf the component count differs from rank().
Exceptions::IndexErrorIf the view is empty or a component is out of bounds.
Complexity
O(rank()).

Definition at line 407 of file ArrayView.hpp.

◆ at() [3/4]

template<typename T >
reference stratax::core::ArrayView< T >::at ( difference_type  index)
inline

Checked logical flat access with negative indices.

Parameters
indexSigned flat index; -1 selects the last logical element.
Exceptions
Exceptions::IndexErrorIf out of bounds, including every index of an empty view.
Complexity
O(rank()).

Definition at line 376 of file ArrayView.hpp.

◆ at() [4/4]

template<typename T >
const_reference stratax::core::ArrayView< T >::at ( difference_type  index) const
inline

Checked logical flat access with negative indices.

Parameters
indexSigned flat index; -1 selects the last logical element.
Exceptions
Exceptions::IndexErrorIf out of bounds, including every index of an empty view.
Complexity
O(rank()).

Definition at line 386 of file ArrayView.hpp.

◆ begin() [1/2]

template<typename T >
const_iterator stratax::core::ArrayView< T >::begin ( ) const
inlinenoexcept

First logical-element iterator.

Complexity
O(1).

Definition at line 306 of file ArrayView.hpp.

◆ begin() [2/2]

template<typename T >
iterator stratax::core::ArrayView< T >::begin ( )
inlinenoexcept

First logical-element iterator.

Complexity
O(1).

Definition at line 304 of file ArrayView.hpp.

◆ cbegin()

template<typename T >
const_iterator stratax::core::ArrayView< T >::cbegin ( ) const
inlinenoexcept

First logical-element iterator.

Complexity
O(1).

Definition at line 308 of file ArrayView.hpp.

◆ cend()

template<typename T >
const_iterator stratax::core::ArrayView< T >::cend ( ) const
inlinenoexcept

Past-the-end iterator.

Complexity
O(rank()).

Definition at line 314 of file ArrayView.hpp.

◆ data() [1/2]

template<typename T >
const_pointer stratax::core::ArrayView< T >::data ( ) const
inlinenoexcept

Read-only base pointer; empty views may have non-null pointers.

Complexity
O(1).

Definition at line 279 of file ArrayView.hpp.

◆ data() [2/2]

template<typename T >
pointer stratax::core::ArrayView< T >::data ( )
inlinenoexcept

Base storage pointer; empty views may have non-null pointers.

Complexity
O(1).

Definition at line 272 of file ArrayView.hpp.

◆ empty()

template<typename T >
bool stratax::core::ArrayView< T >::empty ( ) const
inlinenoexcept

Whether there are no logical elements.

Complexity
O(rank()).

Definition at line 265 of file ArrayView.hpp.

◆ end() [1/2]

template<typename T >
const_iterator stratax::core::ArrayView< T >::end ( ) const
inlinenoexcept

Past-the-end iterator.

Complexity
O(rank()).

Definition at line 312 of file ArrayView.hpp.

◆ end() [2/2]

template<typename T >
iterator stratax::core::ArrayView< T >::end ( )
inlinenoexcept

Past-the-end iterator.

Complexity
O(rank()).

Definition at line 310 of file ArrayView.hpp.

◆ ndim()

template<typename T >
size_type stratax::core::ArrayView< T >::ndim ( ) const
inlinenoexcept

Alias for rank().

Complexity
O(1).

Definition at line 244 of file ArrayView.hpp.

◆ operator()() [1/2]

template<typename T >
template<typename... Rest>
requires ((std::is_integral_v<Rest>) && ...)
reference stratax::core::ArrayView< T >::operator() ( size_type  first,
Rest...  rest 
)
inline

Accesses an element using multidimensional indices with rank checking only.

Parameters
firstFirst non-negative axis index.
restRemaining non-negative axis indices.
Precondition
Every component is within its axis extent; bounds are not checked.
Exceptions
Exceptions::RankErrorIf the number of components differs from rank().
Complexity
O(rank()).

Definition at line 326 of file ArrayView.hpp.

◆ operator()() [2/2]

template<typename T >
template<typename... Rest>
requires ((std::is_integral_v<Rest>) && ...)
const_reference stratax::core::ArrayView< T >::operator() ( size_type  first,
Rest...  rest 
) const
inline

Accesses an element using multidimensional indices with rank checking only.

Parameters
firstFirst non-negative axis index.
restRemaining non-negative axis indices.
Precondition
Every component is within its axis extent; bounds are not checked.
Exceptions
Exceptions::RankErrorIf the number of components differs from rank().
Complexity
O(rank()).

Definition at line 354 of file ArrayView.hpp.

◆ operator[]() [1/2]

template<typename T >
reference stratax::core::ArrayView< T >::operator[] ( size_type  index)
inline

Unchecked logical flat access.

Precondition
index < size().
Complexity
O(rank()).

Definition at line 292 of file ArrayView.hpp.

◆ operator[]() [2/2]

template<typename T >
const_reference stratax::core::ArrayView< T >::operator[] ( size_type  index) const
inline

Unchecked logical flat access.

Precondition
index < size().
Complexity
O(rank()).

Definition at line 298 of file ArrayView.hpp.

◆ rank()

template<typename T >
size_type stratax::core::ArrayView< T >::rank ( ) const
inlinenoexcept

Number of logical axes.

Complexity
O(1).

Definition at line 251 of file ArrayView.hpp.

◆ shape()

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

Logical extents.

Complexity
O(1).

Definition at line 230 of file ArrayView.hpp.

◆ size()

template<typename T >
size_type stratax::core::ArrayView< T >::size ( ) const
inlinenoexcept

Number of logical elements, zero for rank zero.

Complexity
O(rank()).

Definition at line 258 of file ArrayView.hpp.

◆ strides()

template<typename T >
const Shape & stratax::core::ArrayView< T >::strides ( ) const
inlinenoexcept

Stored element strides.

Complexity
O(1).

Definition at line 237 of file ArrayView.hpp.


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