4#include <initializer_list>
7#include <stratax/core/containers/Buffer.hpp>
8#include <stratax/core/Concepts.hpp>
9#include <stratax/core/containers/Shape.hpp>
10#include <stratax/core/containers/Strides.hpp>
11#include <stratax/core/Exceptions.hpp>
14namespace stratax::container {
83 : shape_(core::validation::require_rank(
shape, 1,
"Shape must be rank 1")),
85 buffer_(shape_.elements())
156 T& operator()(std::
size_t index) noexcept
158 return buffer_[index];
171 return buffer_[index];
184 return buffer_[index];
197 return buffer_[index];
209 T&
at(std::ptrdiff_t index)
211 const std::size_t normalized =
212 core::validation::normalize_index(index,
size(),
"Vector index out of bounds.");
213 return buffer_[normalized];
225 const T&
at(std::ptrdiff_t index)
const
227 const std::size_t normalized =
228 core::validation::normalize_index(index,
size(),
"Vector index out of bounds.");
229 return buffer_[normalized];
239 return buffer_.front();
249 return buffer_.front();
259 return buffer_.back();
269 return buffer_.back();
277 [[nodiscard]] std::size_t
size() const noexcept
279 return shape_.elements();
287 [[nodiscard]] std::size_t
rank() const noexcept
289 return shape_.rank();
297 [[nodiscard]]
bool empty() const noexcept
299 return buffer_.empty();
327 [[nodiscard]] T*
data() noexcept
329 return buffer_.data();
337 [[nodiscard]]
const T*
data() const noexcept
339 return buffer_.data();
349 return buffer_.begin();
359 return buffer_.begin();
369 return buffer_.cbegin();
379 return buffer_.end();
389 return buffer_.end();
399 return buffer_.cend();
409 return buffer_.rbegin();
419 return buffer_.rbegin();
429 return buffer_.crbegin();
439 return buffer_.rend();
449 return buffer_.rend();
459 return buffer_.crend();
481 swap(shape_, other.shape_);
482 swap(strides_, other.strides_);
483 swap(buffer_, other.buffer_);
Shared runtime validation helpers.
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.
typename core::Buffer< T >::const_iterator const_iterator
Const iterator over vector elements.
const_iterator cend() const noexcept
Returns a const iterator one past the last element.
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the last element.
iterator begin() noexcept
Returns an iterator to the first element.
T & back()
Returns the last element.
T * data() noexcept
Returns the raw data pointer.
typename core::Buffer< T >::const_reverse_iterator const_reverse_iterator
Const reverse iterator over vector elements.
Vector(Vector &&) noexcept=default
Transfers ownership from another vector.
const T * data() const noexcept
Returns the raw data pointer as a const pointer.
typename core::Buffer< T >::reverse_iterator reverse_iterator
Mutable reverse iterator over vector elements.
T & at(std::ptrdiff_t index)
Returns a flat element with bounds checking.
reverse_iterator rend() noexcept
Returns a reverse iterator before the first element.
T & front()
Returns the first element.
void fill(const T &value)
Fills every element with the same value.
const T & front() const
Returns the first element as a const reference.
bool empty() const noexcept
Returns whether the vector has no elements.
const stratax::core::Shape & shape() const noexcept
std::size_t rank() const noexcept
Returns the vector rank.
std::size_t size() const noexcept
const T & operator()(std::size_t index) const noexcept
Returns a flat element without bounds checking.
void swap(Vector &other) noexcept
Swaps the contents of two vectors.
typename core::Buffer< T >::iterator iterator
Mutable iterator over vector elements.
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator before the first element.
const stratax::core::Strides & strides() const noexcept
Returns the vector strides.
T & operator[](std::size_t index) noexcept
Returns a flat element without bounds checking.
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the last element.
T value_type
Element type stored by the vector.
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator before the first element.
Vector< U > rebind
Rebinds the vector container to another element type.
Vector(const core::Shape &shape)
Creates a vector from a validated rank-1 shape.
Vector() noexcept=default
Creates a default vector with no logical dimensions.
const_iterator cbegin() const noexcept
Returns a const iterator to the first element.
Vector(std::initializer_list< T > list)
Creates a vector from an initializer list.
const T & operator[](std::size_t index) const noexcept
Returns a flat element without bounds checking.
Vector(std::size_t size, const T &value)
Creates a vector and fills it with a value.
const_iterator begin() const noexcept
Returns a const iterator to the first element.
const T & at(std::ptrdiff_t index) const
Returns a flat element with bounds checking.
const T & back() const
Returns the last element as a const reference.
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the last element.
Vector(const Vector &)=default
Creates a copy of another vector.
Owns contiguous dynamically allocated storage.
std::reverse_iterator< iterator > reverse_iterator
Mutable reverse iterator over contiguous buffer elements.
const T * const_iterator
Const iterator over contiguous buffer elements.
T * iterator
Mutable iterator over contiguous buffer elements.
std::reverse_iterator< const_iterator > const_reverse_iterator
Const reverse iterator over contiguous buffer elements.
Stores a list of dimension lengths for an array shape.
static constexpr allow_zero_t allow_zero
Tag value documenting that zero-valued dimensions are intentional.
Stores strides for a shape in contiguous memory.