Stratax 0.2.0
Loading...
Searching...
No Matches
stratax::core::Shape Class Reference

Stores a list of dimension lengths for an array shape. More...

#include <Shape.hpp>

Classes

struct  allow_zero_t
 Tag type documenting that zero-valued dimensions are intentional. More...

Public Types

using iterator = Buffer<std::size_t>::iterator
 Mutable iterator over dimension lengths.
using const_iterator = Buffer<std::size_t>::const_iterator
 Const iterator over dimension lengths.
using reverse_iterator = Buffer<std::size_t>::reverse_iterator
 Mutable reverse iterator over dimension lengths.
using const_reverse_iterator = Buffer<std::size_t>::const_reverse_iterator
 Const reverse iterator over dimension lengths.

Public Member Functions

 Shape () noexcept=default
 Creates an empty shape.
template<Integral... Dims>
requires (sizeof...(Dims) > 0)
 Shape (Dims... dims)
 Creates a shape from non-negative integer dimension lengths.
 Shape (std::initializer_list< std::size_t > list, allow_zero_t allow_zero)
 Creates a shape from dimension lengths using the explicit zero-dimension tag.
 Shape (const Buffer< std::size_t > &dims)
 Creates a shape by copying dimension lengths from a buffer.
 Shape (const Buffer< std::size_t > &dims, allow_zero_t allow_zero)
 Creates a shape by copying dimension lengths using the explicit zero-dimension tag.
 Shape (Buffer< std::size_t > &&dims)
 Creates a shape by taking ownership of dimension lengths from a buffer.
 Shape (const std::vector< std::size_t > &dims)
 Creates a shape by copying dimension lengths from a standard vector.
 ~Shape ()=default
 Destroys the shape.
std::size_t elements () const
 Returns the total number of elements described by the shape.
std::size_t rank () const
 Returns the number of stored dimensions.
const std::size_t & operator() (std::size_t index) const
 Returns the length of a specific dimension.
const std::size_t & operator[] (std::ptrdiff_t index) const
 Returns the length of a specific dimension using signed indexing.
bool empty () const noexcept
 Returns whether the shape has no dimensions.
bool operator== (const Shape &other) const noexcept
 Compares two shapes for exact rank and dimension equality.
bool operator!= (const Shape &other) const noexcept
 Returns whether two shapes differ in rank or dimension values.
iterator begin () noexcept
 Returns an iterator to the first stored dimension.
iterator end () noexcept
 Returns an iterator one past the last stored dimension.
const_iterator begin () const noexcept
 Returns a const iterator to the first stored dimension.
const_iterator end () const noexcept
 Returns a const iterator one past the last stored dimension.
const_iterator cbegin () const noexcept
 Returns a const iterator to the first stored dimension.
const_iterator cend () const noexcept
 Returns a const iterator one past the last stored dimension.
reverse_iterator rbegin () noexcept
 Returns a reverse iterator to the last stored dimension.
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the last stored dimension.
const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the last stored dimension.
reverse_iterator rend () noexcept
 Returns a reverse iterator before the first stored dimension.
const_reverse_iterator rend () const noexcept
 Returns a const reverse iterator before the first stored dimension.
const_reverse_iterator crend () const noexcept
 Returns a const reverse iterator before the first stored dimension.
void swap (Shape &other) noexcept
 Swaps the stored dimensions with another shape.

Static Public Attributes

static constexpr allow_zero_t allow_zero {}
 Tag value documenting that zero-valued dimensions are intentional.

Detailed Description

Stores a list of dimension lengths for an array shape.

Shape tracks rank, dimension sizes, and derived element counts for Stratax containers. It provides lightweight metadata only and does not own any element storage.

Definition at line 21 of file Shape.hpp.

Member Typedef Documentation

◆ const_iterator

using stratax::core::Shape::const_iterator = Buffer<std::size_t>::const_iterator

Const iterator over dimension lengths.

Definition at line 47 of file Shape.hpp.

◆ const_reverse_iterator

using stratax::core::Shape::const_reverse_iterator = Buffer<std::size_t>::const_reverse_iterator

Const reverse iterator over dimension lengths.

Definition at line 53 of file Shape.hpp.

◆ iterator

using stratax::core::Shape::iterator = Buffer<std::size_t>::iterator

Mutable iterator over dimension lengths.

Definition at line 44 of file Shape.hpp.

◆ reverse_iterator

using stratax::core::Shape::reverse_iterator = Buffer<std::size_t>::reverse_iterator

Mutable reverse iterator over dimension lengths.

Definition at line 50 of file Shape.hpp.

Constructor & Destructor Documentation

◆ Shape() [1/7]

stratax::core::Shape::Shape ( )
defaultnoexcept

Creates an empty shape.

An empty shape has rank 0 and stores no axis lengths.

◆ Shape() [2/7]

template<Integral... Dims>
requires (sizeof...(Dims) > 0)
stratax::core::Shape::Shape ( Dims... dims)
inline

Creates a shape from non-negative integer dimension lengths.

The dimensions are stored in order, from outermost axis to innermost axis. Boolean and character-like types are rejected by the Integral concept.

Parameters
dimsDimension lengths.

Definition at line 73 of file Shape.hpp.

◆ Shape() [3/7]

stratax::core::Shape::Shape ( std::initializer_list< std::size_t > list,
allow_zero_t allow_zero )
inline

Creates a shape from dimension lengths using the explicit zero-dimension tag.

This overload documents zero-preserving construction for call sites that want to make that intent visible.

Parameters
listDimension lengths.
allow_zeroTag documenting that zero-valued dimensions are intentional.

Definition at line 88 of file Shape.hpp.

◆ Shape() [4/7]

stratax::core::Shape::Shape ( const Buffer< std::size_t > & dims)
inline

Creates a shape by copying dimension lengths from a buffer.

Parameters
dimsSource buffer containing one dimension length per entry.

Definition at line 98 of file Shape.hpp.

◆ Shape() [5/7]

stratax::core::Shape::Shape ( const Buffer< std::size_t > & dims,
allow_zero_t allow_zero )
inline

Creates a shape by copying dimension lengths using the explicit zero-dimension tag.

Parameters
dimsSource buffer containing one dimension length per entry.
allow_zeroTag documenting that zero-valued dimensions are intentional.

Definition at line 110 of file Shape.hpp.

◆ Shape() [6/7]

stratax::core::Shape::Shape ( Buffer< std::size_t > && dims)
inline

Creates a shape by taking ownership of dimension lengths from a buffer.

Parameters
dimsSource buffer containing one dimension length per entry.

Definition at line 121 of file Shape.hpp.

◆ Shape() [7/7]

stratax::core::Shape::Shape ( const std::vector< std::size_t > & dims)
inline

Creates a shape by copying dimension lengths from a standard vector.

Parameters
dimsSource vector containing one dimension length per entry.

Definition at line 132 of file Shape.hpp.

Member Function Documentation

◆ begin() [1/2]

const_iterator stratax::core::Shape::begin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first stored dimension.

Returns
Const iterator to the beginning of the dimension storage.

Definition at line 282 of file Shape.hpp.

◆ begin() [2/2]

iterator stratax::core::Shape::begin ( )
inlinenodiscardnoexcept

Returns an iterator to the first stored dimension.

Returns
Iterator to the beginning of the dimension storage.

Definition at line 262 of file Shape.hpp.

◆ cbegin()

const_iterator stratax::core::Shape::cbegin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first stored dimension.

Returns
Const iterator to the beginning of the dimension storage.

Definition at line 302 of file Shape.hpp.

◆ cend()

const_iterator stratax::core::Shape::cend ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last stored dimension.

Returns
Const iterator to the end of the dimension storage.

Definition at line 312 of file Shape.hpp.

◆ crbegin()

const_reverse_iterator stratax::core::Shape::crbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last stored dimension.

Returns
Const reverse iterator starting at the last stored dimension.

Definition at line 342 of file Shape.hpp.

◆ crend()

const_reverse_iterator stratax::core::Shape::crend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first stored dimension.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 372 of file Shape.hpp.

◆ elements()

std::size_t stratax::core::Shape::elements ( ) const
inlinenodiscard

Returns the total number of elements described by the shape.

The result is the product of all stored dimensions. An empty shape reports zero elements.

Returns
Total number of elements implied by the shape.
Exceptions
Exceptions::DimensionErrorIf the product of dimensions would overflow std::size_t.

Definition at line 157 of file Shape.hpp.

◆ empty()

bool stratax::core::Shape::empty ( ) const
inlinenodiscardnoexcept

Returns whether the shape has no dimensions.

Returns
true when the shape rank is zero.

Definition at line 217 of file Shape.hpp.

◆ end() [1/2]

const_iterator stratax::core::Shape::end ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last stored dimension.

Returns
Const iterator to the end of the dimension storage.

Definition at line 292 of file Shape.hpp.

◆ end() [2/2]

iterator stratax::core::Shape::end ( )
inlinenodiscardnoexcept

Returns an iterator one past the last stored dimension.

Returns
Iterator to the end of the dimension storage.

Definition at line 272 of file Shape.hpp.

◆ operator!=()

bool stratax::core::Shape::operator!= ( const Shape & other) const
inlinenodiscardnoexcept

Returns whether two shapes differ in rank or dimension values.

Parameters
otherShape to compare against.
Returns
true when the shapes are not equal.

Definition at line 252 of file Shape.hpp.

◆ operator()()

const std::size_t & stratax::core::Shape::operator() ( std::size_t index) const
inline

Returns the length of a specific dimension.

Parameters
indexZero-based dimension index.
Returns
Dimension length at the requested index.
Exceptions
Exceptions::IndexErrorIf index is greater than or equal to the shape rank.

Definition at line 190 of file Shape.hpp.

◆ operator==()

bool stratax::core::Shape::operator== ( const Shape & other) const
inlinenodiscardnoexcept

Compares two shapes for exact rank and dimension equality.

Parameters
otherShape to compare against.
Returns
true when both shapes have the same rank and dimension values.

Definition at line 229 of file Shape.hpp.

◆ operator[]()

const std::size_t & stratax::core::Shape::operator[] ( std::ptrdiff_t index) const
inline

Returns the length of a specific dimension using signed indexing.

Negative indices address dimensions from the end of the shape.

Parameters
indexSigned dimension index.
Returns
Dimension length at the requested index.
Exceptions
Exceptions::IndexErrorIf index is out of bounds.

Definition at line 207 of file Shape.hpp.

◆ rank()

std::size_t stratax::core::Shape::rank ( ) const
inlinenodiscard

Returns the number of stored dimensions.

Returns
Shape rank.

Definition at line 176 of file Shape.hpp.

◆ rbegin() [1/2]

const_reverse_iterator stratax::core::Shape::rbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last stored dimension.

Returns
Const reverse iterator starting at the last stored dimension.

Definition at line 332 of file Shape.hpp.

◆ rbegin() [2/2]

reverse_iterator stratax::core::Shape::rbegin ( )
inlinenodiscardnoexcept

Returns a reverse iterator to the last stored dimension.

Returns
Reverse iterator starting at the last stored dimension.

Definition at line 322 of file Shape.hpp.

◆ rend() [1/2]

const_reverse_iterator stratax::core::Shape::rend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first stored dimension.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 362 of file Shape.hpp.

◆ rend() [2/2]

reverse_iterator stratax::core::Shape::rend ( )
inlinenodiscardnoexcept

Returns a reverse iterator before the first stored dimension.

Returns
Reverse iterator representing the end sentinel.

Definition at line 352 of file Shape.hpp.

◆ swap()

void stratax::core::Shape::swap ( Shape & other)
inlinenoexcept

Swaps the stored dimensions with another shape.

Parameters
otherShape to exchange state with.

Definition at line 382 of file Shape.hpp.

Member Data Documentation

◆ allow_zero

allow_zero_t stratax::core::Shape::allow_zero {}
staticconstexpr

Tag value documenting that zero-valued dimensions are intentional.

Definition at line 41 of file Shape.hpp.


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