template<typename T>
Vector2 class

Public types

using value_type = T

Constructors, destructors, conversion operators

Vector2(size_t size)
Vector2(const std::vector<T>& v)
~Vector2() defaulted

Public functions

auto operator[](size_t i) -> T&
auto operator[](size_t i) const -> const T&
auto size() const -> size_t
auto operator+=(const Vector2& rhs) -> Vector2&
auto operator-=(const Vector2& rhs) -> Vector2&
auto operator*=(T scalar) -> Vector2&
auto dot(const Vector2& other) const -> T
auto norm() const -> T

Function documentation

template<typename T>
Vector2<T>::Vector2(size_t size)

Parameters
size The size of the Vector2.

Constructs a Vector2 with the given size, initializing all elements to the default value of T.

template<typename T>
Vector2<T>::Vector2(const std::vector<T>& v)

Parameters
v The std::vector to initialize the Vector2 with.

Constructs a Vector2 from a std::vector.

template<typename T>
Vector2<T>::~Vector2() defaulted

Returns None

Destroys the Vector2 object.

template<typename T>
T& Vector2<T>::operator[](size_t i)

Parameters
i The index of the element to access.
Returns A reference to the element at the specified index.

Provides access to the elements of the Vector2 object.

template<typename T>
const T& Vector2<T>::operator[](size_t i) const

Parameters
i The index of the element to access.
Returns A constant reference to the element at the specified index.

Provides constant access to the elements of the Vector2 object.

template<typename T>
size_t Vector2<T>::size() const

Returns The size of the Vector2 object.

Returns the size of the Vector2 object.

template<typename T>
Vector2& Vector2<T>::operator+=(const Vector2& rhs)

Parameters
rhs The Vector2 to add to this Vector2.
Returns A reference to this Vector2 after the addition.

Adds the elements of the given Vector2 to the corresponding elements of this Vector2.

template<typename T>
Vector2& Vector2<T>::operator-=(const Vector2& rhs)

Parameters
rhs The Vector2 to subtract from this Vector2.
Returns A reference to this Vector2 after the subtraction.

Subtracts the elements of the given Vector2 from the corresponding elements of this Vector2.

template<typename T>
Vector2& Vector2<T>::operator*=(T scalar)

Parameters
scalar The scalar value to multiply the Vector2 elements by.
Returns A reference to this Vector2 after the multiplication.

Multiplies each element of the Vector2 by the given scalar value.

template<typename T>
T Vector2<T>::dot(const Vector2& other) const

Parameters
other The other Vector2 to compute the dot product with.
Returns The dot product of this Vector2 and the given Vector2.

Computes the dot product of this Vector2 with the given Vector2.

template<typename T>
T Vector2<T>::norm() const

Returns The L2 norm of the Vector2.

Computes the L2 norm (Euclidean length) of the Vector2.