21 template <
typename T,
unsigned DIM>
requires
22 (DIM > 0) && std::is_standard_layout_v<T> && std::is_trivially_copyable_v<T>
28 static constexpr size_t vec_size = DIM;
48 constexpr Vector() noexcept = default;
79 constexpr ~
Vector() noexcept = default;
86 std::fill(std::begin(m_elements), std::end(m_elements), val);
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));
168 return m_elements[i % DIM];
182 return m_elements[i % DIM];
190 return m_elements.begin();
197 constexpr auto end() noexcept {
198 return m_elements.end();
206 return m_elements.cbegin();
213 constexpr auto cend() const noexcept {
214 return m_elements.cend();
223 return m_elements.data();
229 constexpr operator std::array<T, DIM>() const noexcept {
236 constexpr operator std::vector<T>()
const {
237 return std::vector<T>(std::begin(m_elements), std::end(m_elements));
244 constexpr int size() const noexcept {
253 return m_elements[0];
261 return m_elements[0];
269 return m_elements[1];
277 return m_elements[1];
285 return m_elements[2];
293 return m_elements[2];
301 return m_elements[3];
309 return m_elements[3];
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
Returns the value of the w component of the vector.
Definition vector.hpp:300
constexpr scalar_type x() const noexcept
Returns the value of the x component of the vector.
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
Returns the value of the z component of the vector.
Definition vector.hpp:284
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
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
Returns the value of the y component of the vector.
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
constexpr scalar_type & y() noexcept
Returns a reference of the value of the y component of the vector.
Definition vector.hpp:276