Stratax 0.2.0
Loading...
Searching...
No Matches
stratax::core::Buffer< T, Alignment > Class Template Reference

Owns contiguous dynamically allocated storage. More...

#include <Buffer.hpp>

Classes

struct  uninitialized_t
 Tag type selecting allocated storage without element initialization. More...

Public Types

using iterator = T*
 Mutable iterator over contiguous buffer elements.
using const_iterator = const T*
 Const iterator over contiguous buffer elements.
using reverse_iterator = std::reverse_iterator<iterator>
 Mutable reverse iterator over contiguous buffer elements.
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 Const reverse iterator over contiguous buffer elements.

Public Member Functions

 Buffer () noexcept
 Creates an empty buffer.
 Buffer (std::size_t size)
 Creates a buffer with default-initialized elements.
 Buffer (std::size_t size, uninitialized_t uninitialized)
 Creates a buffer with allocated but uninitialized storage.
 Buffer (std::size_t size, const T &value)
 Creates a buffer and fills every element with a value.
 Buffer (std::initializer_list< T > list)
 Creates a buffer from an initializer list.
 Buffer (const Buffer &other)
 Creates a copy of another buffer.
 Buffer (Buffer &&other) noexcept
 Transfers ownership from another buffer.
Bufferoperator= (const Buffer &other)
 Replaces this buffer with a copy of another buffer.
Bufferoperator= (Buffer &&other) noexcept
 Replaces this buffer by taking ownership from another buffer.
 ~Buffer ()
 Releases the owned storage.
T & operator[] (std::size_t index) noexcept
 Returns a mutable element reference without bounds checking.
const T & operator[] (std::size_t index) const noexcept
 Returns a const element reference without 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.
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.
std::size_t size () const noexcept
 Returns the number of stored elements.
bool empty () const noexcept
 Returns whether the buffer contains no elements.
void fill (const T &value)
 Fills every element with the same value.
void swap (Buffer &other) noexcept
 Swaps the contents of two buffers.

Static Public Attributes

static constexpr uninitialized_t uninitialized {}
 Tag value selecting allocated storage without element initialization.

Detailed Description

template<typename T, std::size_t Alignment = config::default_alignment>
class stratax::core::Buffer< T, Alignment >

Owns contiguous dynamically allocated storage.

Buffer is the low-level memory container used by Stratax arrays. It manages allocation, destruction, and flat element access, while higher-level types such as Vector, Matrix, and Tensor handle shape semantics and mathematical operations.

The stored elements are always contiguous in memory, and the buffer follows RAII so ownership is released automatically when the object is destroyed.

Template Parameters
TElement type.
AlignmentAlignment used for allocation, defaulting to 64.
Note
Buffer provides storage only. It does not validate shapes or perform multidimensional indexing.

Definition at line 38 of file Buffer.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T, std::size_t Alignment = config::default_alignment>
using stratax::core::Buffer< T, Alignment >::const_iterator = const T*

Const iterator over contiguous buffer elements.

Definition at line 50 of file Buffer.hpp.

◆ const_reverse_iterator

template<typename T, std::size_t Alignment = config::default_alignment>
using stratax::core::Buffer< T, Alignment >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Const reverse iterator over contiguous buffer elements.

Definition at line 56 of file Buffer.hpp.

◆ iterator

template<typename T, std::size_t Alignment = config::default_alignment>
using stratax::core::Buffer< T, Alignment >::iterator = T*

Mutable iterator over contiguous buffer elements.

Definition at line 47 of file Buffer.hpp.

◆ reverse_iterator

template<typename T, std::size_t Alignment = config::default_alignment>
using stratax::core::Buffer< T, Alignment >::reverse_iterator = std::reverse_iterator<iterator>

Mutable reverse iterator over contiguous buffer elements.

Definition at line 53 of file Buffer.hpp.

Constructor & Destructor Documentation

◆ Buffer() [1/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( )
inlinenoexcept

Creates an empty buffer.

The buffer owns no storage and contains zero elements.

Definition at line 63 of file Buffer.hpp.

◆ Buffer() [2/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( std::size_t size)
inlineexplicit

Creates a buffer with default-initialized elements.

The buffer allocates storage for the requested number of elements and default-constructs each one in place.

Parameters
sizeNumber of elements to allocate.

Definition at line 73 of file Buffer.hpp.

◆ Buffer() [3/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( std::size_t size,
uninitialized_t uninitialized )
inline

Creates a buffer with allocated but uninitialized storage.

Use this overload when you intend to construct the elements later and want to avoid default initialization work.

Parameters
sizeNumber of elements to allocate.
uninitializedTag selecting uninitialized storage.
Warning
The element type must be trivially destructible.

Definition at line 89 of file Buffer.hpp.

◆ Buffer() [4/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( std::size_t size,
const T & value )
inline

Creates a buffer and fills every element with a value.

Each element is copy-constructed from the supplied value.

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

Definition at line 106 of file Buffer.hpp.

◆ Buffer() [5/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( std::initializer_list< T > list)
inline

Creates a buffer from an initializer list.

The elements are copied in list order.

Parameters
listSource values to copy into the buffer.

Definition at line 118 of file Buffer.hpp.

◆ Buffer() [6/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( const Buffer< T, Alignment > & other)
inline

Creates a copy of another buffer.

The new buffer owns its own storage and duplicates the source elements.

Parameters
otherBuffer to copy from.

Definition at line 142 of file Buffer.hpp.

◆ Buffer() [7/7]

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::Buffer ( Buffer< T, Alignment > && other)
inlinenoexcept

Transfers ownership from another buffer.

The source buffer is left empty after the move.

Parameters
otherBuffer to move from.

Definition at line 172 of file Buffer.hpp.

◆ ~Buffer()

template<typename T, std::size_t Alignment = config::default_alignment>
stratax::core::Buffer< T, Alignment >::~Buffer ( )
inline

Releases the owned storage.

Destroying a buffer also destroys any constructed elements before the memory is returned to the allocator.

Definition at line 232 of file Buffer.hpp.

Member Function Documentation

◆ back() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
T & stratax::core::Buffer< T, Alignment >::back ( )
inline

Returns the last element.

Returns
Mutable reference to the last stored element.
Exceptions
Exceptions::IndexErrorIf the buffer is empty.

Definition at line 305 of file Buffer.hpp.

◆ back() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const T & stratax::core::Buffer< T, Alignment >::back ( ) const
inline

Returns the last element as a const reference.

Returns
Const reference to the last stored element.
Exceptions
Exceptions::IndexErrorIf the buffer is empty.

Definition at line 321 of file Buffer.hpp.

◆ begin() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const_iterator stratax::core::Buffer< T, Alignment >::begin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first element.

Returns
Const iterator to the beginning of the buffer.

Definition at line 365 of file Buffer.hpp.

◆ begin() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
iterator stratax::core::Buffer< T, Alignment >::begin ( )
inlinenodiscardnoexcept

Returns an iterator to the first element.

Returns
Iterator to the beginning of the buffer.

Definition at line 355 of file Buffer.hpp.

◆ cbegin()

template<typename T, std::size_t Alignment = config::default_alignment>
const_iterator stratax::core::Buffer< T, Alignment >::cbegin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first element.

Returns
Const iterator to the beginning of the buffer.

Definition at line 375 of file Buffer.hpp.

◆ cend()

template<typename T, std::size_t Alignment = config::default_alignment>
const_iterator stratax::core::Buffer< T, Alignment >::cend ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last element.

Returns
Const iterator to the end of the buffer.

Definition at line 405 of file Buffer.hpp.

◆ crbegin()

template<typename T, std::size_t Alignment = config::default_alignment>
const_reverse_iterator stratax::core::Buffer< T, Alignment >::crbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last element.

Returns
Const reverse iterator starting at the last element.

Definition at line 435 of file Buffer.hpp.

◆ crend()

template<typename T, std::size_t Alignment = config::default_alignment>
const_reverse_iterator stratax::core::Buffer< T, Alignment >::crend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first element.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 465 of file Buffer.hpp.

◆ data() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const T * stratax::core::Buffer< T, Alignment >::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 345 of file Buffer.hpp.

◆ data() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
T * stratax::core::Buffer< T, Alignment >::data ( )
inlinenodiscardnoexcept

Returns the raw data pointer.

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

Definition at line 335 of file Buffer.hpp.

◆ empty()

template<typename T, std::size_t Alignment = config::default_alignment>
bool stratax::core::Buffer< T, Alignment >::empty ( ) const
inlinenodiscardnoexcept

Returns whether the buffer contains no elements.

Returns
true when the buffer is empty; otherwise false.

Definition at line 485 of file Buffer.hpp.

◆ end() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const_iterator stratax::core::Buffer< T, Alignment >::end ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last element.

Returns
Const iterator to the end of the buffer.

Definition at line 395 of file Buffer.hpp.

◆ end() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
iterator stratax::core::Buffer< T, Alignment >::end ( )
inlinenodiscardnoexcept

Returns an iterator one past the last element.

Returns
Iterator to the end of the buffer.

Definition at line 385 of file Buffer.hpp.

◆ fill()

template<typename T, std::size_t Alignment = config::default_alignment>
void stratax::core::Buffer< T, Alignment >::fill ( const T & value)
inline

Fills every element with the same value.

Parameters
valueValue to assign to each element.

Definition at line 495 of file Buffer.hpp.

◆ front() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
T & stratax::core::Buffer< T, Alignment >::front ( )
inline

Returns the first element.

Returns
Mutable reference to the first stored element.
Exceptions
Exceptions::IndexErrorIf the buffer is empty.

Definition at line 273 of file Buffer.hpp.

◆ front() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const T & stratax::core::Buffer< T, Alignment >::front ( ) const
inline

Returns the first element as a const reference.

Returns
Const reference to the first stored element.
Exceptions
Exceptions::IndexErrorIf the buffer is empty.

Definition at line 289 of file Buffer.hpp.

◆ operator=() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
Buffer & stratax::core::Buffer< T, Alignment >::operator= ( Buffer< T, Alignment > && other)
inlinenoexcept

Replaces this buffer by taking ownership from another buffer.

The current contents are destroyed before the source storage is adopted.

Parameters
otherBuffer to move from.
Returns
Reference to this buffer.

Definition at line 209 of file Buffer.hpp.

◆ operator=() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
Buffer & stratax::core::Buffer< T, Alignment >::operator= ( const Buffer< T, Alignment > & other)
inline

Replaces this buffer with a copy of another buffer.

This assignment provides the strong exception guarantee by copying into a temporary buffer first.

Parameters
otherBuffer to copy from.
Returns
Reference to this buffer.

Definition at line 189 of file Buffer.hpp.

◆ operator[]() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const T & stratax::core::Buffer< T, Alignment >::operator[] ( std::size_t index) const
inlinenoexcept

Returns a const element reference 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 261 of file Buffer.hpp.

◆ operator[]() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
T & stratax::core::Buffer< T, Alignment >::operator[] ( std::size_t index)
inlinenoexcept

Returns a mutable element reference without bounds checking.

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

Definition at line 247 of file Buffer.hpp.

◆ rbegin() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const_reverse_iterator stratax::core::Buffer< T, Alignment >::rbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last element.

Returns
Const reverse iterator starting at the last element.

Definition at line 425 of file Buffer.hpp.

◆ rbegin() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
reverse_iterator stratax::core::Buffer< T, Alignment >::rbegin ( )
inlinenodiscardnoexcept

Returns a reverse iterator to the last element.

Returns
Reverse iterator starting at the last element.

Definition at line 415 of file Buffer.hpp.

◆ rend() [1/2]

template<typename T, std::size_t Alignment = config::default_alignment>
const_reverse_iterator stratax::core::Buffer< T, Alignment >::rend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first element.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 455 of file Buffer.hpp.

◆ rend() [2/2]

template<typename T, std::size_t Alignment = config::default_alignment>
reverse_iterator stratax::core::Buffer< T, Alignment >::rend ( )
inlinenodiscardnoexcept

Returns a reverse iterator before the first element.

Returns
Reverse iterator representing the end sentinel.

Definition at line 445 of file Buffer.hpp.

◆ size()

template<typename T, std::size_t Alignment = config::default_alignment>
std::size_t stratax::core::Buffer< T, Alignment >::size ( ) const
inlinenodiscardnoexcept

Returns the number of stored elements.

Returns
Number of elements currently owned by the buffer.

Definition at line 475 of file Buffer.hpp.

◆ swap()

template<typename T, std::size_t Alignment = config::default_alignment>
void stratax::core::Buffer< T, Alignment >::swap ( Buffer< T, Alignment > & other)
inlinenoexcept

Swaps the contents of two buffers.

Parameters
otherBuffer to exchange state with.

Definition at line 505 of file Buffer.hpp.

Member Data Documentation

◆ uninitialized

template<typename T, std::size_t Alignment = config::default_alignment>
uninitialized_t stratax::core::Buffer< T, Alignment >::uninitialized {}
staticconstexpr

Tag value selecting allocated storage without element initialization.

Definition at line 44 of file Buffer.hpp.


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