21 template <
typename T,
unsigned DIM>
requires
22 (DIM > 0) && std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>
48 constexpr Vector() noexcept = default;
79 constexpr ~
Vector() noexcept = default;
94 constexpr Vector(T
x, T
y)
noexcept requires(DIM == 2)
108 constexpr Vector(T
x, T
y, T
z)
noexcept requires(DIM == 3)
124 constexpr Vector(T
x, T
y, T
z, T
w)
noexcept requires(DIM == 4)
138 constexpr explicit Vector(std::ranges::input_range
auto&& input)
noexcept requires
139 std::is_nothrow_convertible_v<std::ranges::range_value_t<
decltype(input)>, T>
141 std::ranges::copy(input, std::begin(
m_elements));
149 constexpr auto&
operator=(std::ranges::input_range
auto&& input)
noexcept requires
150 std::is_nothrow_convertible_v<std::ranges::range_value_t<
decltype(input)>, T>
152 std::ranges::copy(input, std::begin(
m_elements));
197 constexpr auto end() noexcept {
213 constexpr auto cend() const noexcept {
229 constexpr operator std::array<T, DIM>() const noexcept {
236 constexpr operator std::vector<T>()
const {
244 constexpr int size() const noexcept {
Vector< T, 1 > TVector1
A generic vector with one component.
Definition vector.hpp:317
Vector< T, 4 > TVector4
A generic vector with four components.
Definition vector.hpp:335
Vector< T, 3 > TVector3
A generic vector with three components.
Definition vector.hpp:329
Vector< T, 2 > TVector2
A generic vector with two components.
Definition vector.hpp:323
An algebraic vector type.
Definition vector.hpp:23
constexpr Vector(T x, T y, T z) noexcept
Initializes a 3D vector using the values provided by x , y and z .
Definition vector.hpp:108
constexpr auto cend() const noexcept
Returns a constant interator for that addresses the end of the vector elements.
Definition vector.hpp:213
constexpr Vector(std::ranges::input_range auto &&input) noexcept
Initializes the vector from an arbitrary input range.
Definition vector.hpp:138
constexpr T & operator[](unsigned int i) noexcept
Returns a reference to a value from the vector, indexed by the parameter i .
Definition vector.hpp:179
std::array< scalar_type, vec_size > array_type
Definition vector.hpp:41
constexpr int size() const noexcept
Returns the number of dimensions of the vector.
Definition vector.hpp:244
constexpr scalar_type w() const noexcept
Definition vector.hpp:300
constexpr scalar_type x() const noexcept
Definition vector.hpp:252
constexpr auto cbegin() const noexcept
Returns a constant interator for that addresses the begin of the vector elements.
Definition vector.hpp:205
constexpr const scalar_type * elements() const noexcept
Returns a pointer to the elements of the vector.
Definition vector.hpp:222
constexpr auto & operator=(std::ranges::input_range auto &&input) noexcept
Copies the values from an arbitrary input range into the current vector instance.
Definition vector.hpp:149
constexpr scalar_type z() const noexcept
Definition vector.hpp:284
Vector< scalar_type, vec_size > vec_type
The type of the vector itself.
Definition vector.hpp:38
constexpr scalar_type & x() noexcept
Returns a reference of the value of the x component of the vector.
Definition vector.hpp:260
constexpr Vector(T x, T y) noexcept
Initializes a 2D vector using the values provided by x and y .
Definition vector.hpp:94
constexpr auto end() noexcept
Returns an interator for that addresses the end of the vector elements.
Definition vector.hpp:197
constexpr scalar_type & w() noexcept
Returns a reference of the value of the w component of the vector.
Definition vector.hpp:308
array_type m_elements
Definition vector.hpp:42
T scalar_type
The type of the vector elements.
Definition vector.hpp:33
constexpr auto begin() noexcept
Returns an interator for that addresses the begin of the vector elements.
Definition vector.hpp:189
constexpr scalar_type y() const noexcept
Definition vector.hpp:268
constexpr scalar_type & z() noexcept
Returns a reference of the value of the z component of the vector.
Definition vector.hpp:292
constexpr T operator[](unsigned int i) const noexcept
Returns a value from the vector, indexed by the parameter i .
Definition vector.hpp:165
constexpr Vector() noexcept=default
Initializes an empty vector.
constexpr Vector(T x, T y, T z, T w) noexcept
Initializes a 4D vector using the values provided by x , y , z and w .
Definition vector.hpp:124
static constexpr size_t vec_size
Definition vector.hpp:28
constexpr scalar_type & y() noexcept
Returns a reference of the value of the y component of the vector.
Definition vector.hpp:276