Version: v0.2.0
Status: Complete
Header: include/stratax/core/containers/Vector.hpp
Overview
Vector<T> is Stratax's rank-1 owning array container for numeric types.
It stores values in contiguous memory and pairs that storage with Shape and Strides metadata to participate in the common container model used across Stratax arrays.
Responsibilities
The Vector class is responsible for:
- Owning contiguous rank-1 element storage
- Exposing shape and stride metadata
- Providing checked and unchecked element access
- Providing iterator access over contiguous storage
- Supporting copy/move ownership semantics
The Vector class is not responsible for:
- Rank-2 or rank-N multidimensional storage semantics
- Broadcasting logic
- High-level numerical algorithms
- Shape transformation outside the rank-1 contract
Relationships
Vector<T>
│
├── shape_ : core::Shape
├── strides_ : core::Strides
└── buffer_ : core::Buffer<T>
Depends on:
Used by:
- Matrix/Tensor conversion paths
- Generic Stratax container utilities
Related classes:
- Shape
- Strides
- Buffer
- Matrix
- Tensor
Internal Data
| Member | Description |
| core::Shape shape_ | Shape metadata (typically rank 1, rank 0 for default state) |
| core::Strides strides_ | Stride metadata for the vector layout |
| core::Buffer<T> buffer_ | Contiguous element storage |
Invariants
The following conditions are always true:
- size() equals shape().elements().
- For constructed rank-1 vectors, rank() == 1 and strides().rank() == 1.
- data() is contiguous and compatible with pointer iteration.
- at(index) performs bounds validation and supports negative indexing.
- operator[] and operator() are unchecked.
Public Interface
Constructors
Default Constructor
Constructs an empty default vector state (rank 0).
Complexity
Throws
Size Constructor
explicit Vector(std::size_t size);
Constructs a rank-1 vector of size default-initialized elements.
Complexity
Throws
Shape Constructor
explicit Vector(const core::Shape& shape);
Constructs from a validated rank-1 shape.
Complexity
Throws
Fill Constructor
Vector(std::size_t size, const T& value);
Constructs a rank-1 vector of size elements, all initialized to value.
Complexity
Throws
Initializer List Constructor
Vector(std::initializer_list<T> list);
Constructs a rank-1 vector from initializer-list values.
Complexity
Throws
Copy Constructor
Vector(const Vector&) = default;
Complexity
Move Constructor
Vector(Vector&&) noexcept = default;
Complexity
Destructor
Complexity
Assignment Operators
Copy Assignment
Vector& operator=(const Vector&) = default;
Complexity
Move Assignment
Vector& operator=(Vector&&) noexcept = default;
Complexity
Methods
size()
[[nodiscard]] std::size_t size() const noexcept;
Returns total number of elements.
Complexity
rank()
[[nodiscard]] std::size_t rank() const noexcept;
Returns the shape rank.
Complexity
empty()
[[nodiscard]] bool empty() const noexcept;
Returns whether the vector contains no elements.
Complexity
shape()
Stores a list of dimension lengths for an array shape.
Returns vector shape metadata.
Complexity
strides()
Stores strides for a shape in contiguous memory.
Returns vector stride metadata.
Complexity
at()
T& at(std::ptrdiff_t index);
const T& at(std::ptrdiff_t index) const;
Returns an element with bounds checking. Negative indices are normalized from the end.
Complexity
Throws
front()
T& front();
const T& front() const;
Returns first element.
Preconditions
- Vector must not be empty.
Complexity
back()
T& back();
const T& back() const;
Returns last element.
Preconditions
- Vector must not be empty.
Complexity
data()
[[nodiscard]] T* data() noexcept;
[[nodiscard]] const T* data() const noexcept;
Returns raw pointer to contiguous storage.
Complexity
Iterators
[[nodiscard]] T* begin() noexcept;
[[nodiscard]] const T* begin() const noexcept;
[[nodiscard]] const T* cbegin() const noexcept;
[[nodiscard]] T* end() noexcept;
[[nodiscard]] const T* end() const noexcept;
[[nodiscard]] const T* cend() const noexcept;
[[nodiscard]] std::reverse_iterator<T*> rbegin() noexcept;
[[nodiscard]] std::reverse_iterator<const T*> rbegin() const noexcept;
[[nodiscard]] std::reverse_iterator<const T*> crbegin() const noexcept;
[[nodiscard]] std::reverse_iterator<T*> rend() noexcept;
[[nodiscard]] std::reverse_iterator<const T*> rend() const noexcept;
[[nodiscard]] std::reverse_iterator<const T*> crend() const noexcept;
Provides forward and reverse iteration over contiguous elements.
Complexity
fill()
void fill(const T& value);
Assigns value to every element.
Complexity
swap()
void swap(Vector& other) noexcept;
Exchanges shape, strides, and storage with another vector.
Complexity
Operators
operator()
T& operator()(std::size_t index) noexcept;
const T& operator()(std::size_t index) const noexcept;
Unchecked flat indexing.
Complexity
operator[]
T& operator[](std::size_t index) noexcept;
const T& operator[](std::size_t index) const noexcept;
Unchecked flat indexing.
Complexity
See Also
T& at(std::ptrdiff_t index);
const T& at(std::ptrdiff_t index) const;
Complexity Summary
| Operation | Complexity |
| Default construction | O(1) |
| Size/shape/fill/list construction | O(n) |
| Copy construction | O(n) |
| Move construction | O(1) |
| Copy assignment | O(n) |
| Move assignment | O(1) |
| Destruction | O(n) |
| size() / rank() / empty() | O(1) |
| shape() / strides() | O(1) |
| operator() / operator[] / at() | O(1) |
| front() / back() | O(1) |
| Iteration | O(n) |
| fill() | O(n) |
| swap() | O(1) |
Examples
Creating Vectors
Accessing Elements
auto x = v[1];
T & at(std::ptrdiff_t index)
Returns a flat element with bounds checking.
Iteration
for (const auto& value : v)
{
std::cout << value << '\n';
}
Design Notes
Vector<T> keeps layout metadata (Shape, Strides) alongside contiguous data storage (Buffer<T>) so it can interoperate consistently with other Stratax containers.
Unchecked accessors are provided for performance-critical paths, while at() offers safe validated indexing including negative index normalization.
Future Improvements
- Add slicing/view utilities for non-owning vector spans
- Add SIMD-specialized fill/copy paths where profitable
- Add optional small-vector optimization (if benchmark-justified)
See Also