4#include <initializer_list>
69 : shape_(
core::validation::require_rank(
shape, 1,
"Shape must be rank 1")),
71 buffer_(shape_.elements())
95 Vector(std::initializer_list<T> list)
142 T& operator()(std::
size_t index) noexcept
144 return buffer_[index];
157 return buffer_[index];
170 return buffer_[index];
183 return buffer_[index];
195 T&
at(std::size_t index)
198 return buffer_[index];
210 const T&
at(std::size_t index)
const
213 return buffer_[index];
223 return buffer_.front();
233 return buffer_.front();
243 return buffer_.back();
253 return buffer_.back();
261 [[nodiscard]] std::size_t
size() const noexcept
263 return shape_.elements();
271 [[nodiscard]] std::size_t
rank() const noexcept
273 return shape_.rank();
281 [[nodiscard]]
bool empty() const noexcept
283 return buffer_.empty();
311 [[nodiscard]] T*
data() noexcept
313 return buffer_.data();
321 [[nodiscard]]
const T*
data() const noexcept
323 return buffer_.data();
333 return buffer_.begin();
341 [[nodiscard]]
const T*
begin() const noexcept
343 return buffer_.begin();
351 [[nodiscard]]
const T*
cbegin() const noexcept
353 return buffer_.cbegin();
361 [[nodiscard]] T*
end() noexcept
363 return buffer_.end();
371 [[nodiscard]]
const T*
end() const noexcept
373 return buffer_.end();
381 [[nodiscard]]
const T*
cend() const noexcept
383 return buffer_.cend();
391 [[nodiscard]] std::reverse_iterator<T*>
rbegin() noexcept
393 return buffer_.rbegin();
401 [[nodiscard]] std::reverse_iterator<const T*>
rbegin() const noexcept
403 return buffer_.rbegin();
411 [[nodiscard]] std::reverse_iterator<const T*>
crbegin() const noexcept
413 return buffer_.crbegin();
421 [[nodiscard]] std::reverse_iterator<T*>
rend() noexcept
423 return buffer_.rend();
431 [[nodiscard]] std::reverse_iterator<const T*>
rend() const noexcept
433 return buffer_.rend();
441 [[nodiscard]] std::reverse_iterator<const T*>
crend() const noexcept
443 return buffer_.crend();
465 swap(shape_, other.shape_);
466 swap(strides_, other.strides_);
467 swap(buffer_, other.buffer_);
Shared runtime validation helpers.
std::reverse_iterator< const T * > crbegin() const noexcept
Returns a const reverse iterator to the last element.
std::reverse_iterator< T * > rbegin() noexcept
Returns a reverse iterator to the last element.
const T & at(std::size_t index) const
Returns a flat element with bounds checking.
T & at(std::size_t index)
Returns a flat element with bounds checking.
T & back()
Returns the last element.
std::reverse_iterator< const T * > rbegin() const noexcept
Returns a const reverse iterator to the last element.
T * data() noexcept
Returns the raw data pointer.
Vector(Vector &&) noexcept=default
Transfers ownership from another vector.
const T * end() const noexcept
Returns a const iterator one past the last element.
const T * data() const noexcept
Returns the raw data pointer as a const pointer.
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 T * cend() const noexcept
Returns a const iterator one past the last element.
const stratax::core::Shape & shape() const noexcept
std::size_t rank() const noexcept
Returns the vector rank.
T * end() noexcept
Returns an iterator one past the last element.
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.
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 T * begin() const noexcept
Returns a const iterator to the first element.
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.
std::reverse_iterator< const T * > crend() const noexcept
Returns a const reverse iterator before the first element.
Vector(std::initializer_list< T > list)
Creates a vector from an initializer list.
const T * cbegin() const noexcept
Returns a const iterator to the first element.
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.
T * begin() noexcept
Returns an iterator to the first element.
const T & back() const
Returns the last element as a const reference.
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.
Vector(const Vector &)=default
Creates a copy of another vector.
Owns contiguous dynamically allocated storage.
Stores a list of dimension lengths for an array shape.
static constexpr allow_zero_t allow_zero
Stores strides for a shape in contiguous memory.
void require_index(std::size_t index, std::size_t size, const char *message)
Requires an index to be less than a size.