Simple-Vector v1.3.0
sl::vec::Vector< T, VDimensions > Class Template Reference

A mathematically vector implementation. More...

#include <Vector.hpp>

Public Types

using value_type = std::remove_cvref_t< T >
 Alias for T, but without modifiers. More...
 
using storage_type = std::array< value_type, dimensions >
 Used storage type. More...
 

Public Member Functions

constexpr Vector () noexcept=default
 Default constructor. More...
 
constexpr ~Vector () noexcept=default
 Default destructor. More...
 
constexpr Vector (const Vector &) noexcept=default
 Default copy-constructor. More...
 
constexpr Vector (Vector &&) noexcept=default
 Default move-constructor. More...
 
template<class... TArgs>
requires std::convertible_to<std::invoke_result_t<TGenerator&>, value_type>
VDimensions<=1) constexpr Vector(TArgs &&...args) noexcept :m_Values{ static_cast< T >(args)... } { } template< std::convertible_to< value_type > T2, auto VOtherDimensions > requires(!std::same_as< T2, value_type >||dimensions !=VOtherDimensions) constexpr explicit Vector(const Vector< T2, VOtherDimensions > &other) { transform_unseq(std::ranges::take_view{ other, std::min(dimensions, VOtherDimensions) }, std::ranges::begin(m_Values), fn::cast_invoke_result< value_type >(std::identity{}));} template< std::invocable TGenerator > constexpr Vector (TGenerator generator)
 Aggregate initialization like constructor. More...
 
constexpr Vectoroperator= (const Vector &) noexcept=default
 Default copy-assign-operator. More...
 
constexpr Vectoroperator= (Vector &&) noexcept=default
 Default move-assign-operator. More...
 
constexpr bool operator== (const Vector &) const noexcept=default
 Default equality comparison operator. More...
 
constexpr const value_typeoperator[] (std::integral auto index) const noexcept
 Accesses a specific element. More...
 
template<std::integral TIndex>
constexpr value_typeoperator[] (std::integral auto index) noexcept
 Accesses a specific element. More...
 
constexpr const value_typex () const noexcept
 Accesses the first element. More...
 
constexpr value_typex () noexcept
 Accesses the first element. More...
 
constexpr const value_typey () const noexcept
 Accesses the second element. More...
 
constexpr value_typey () noexcept
 Accesses the second element. More...
 
constexpr const value_typez () const noexcept
 Accesses the third element. More...
 
constexpr value_typez () noexcept
 Accesses the third element. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator+= (const Vector< T2, dimensions > &other)
 Adds other Vector element-wise. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator-= (const Vector< T2, dimensions > &other)
 Subtracts other Vector element-wise. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator+= (const T2 &value)
 Adds value to each element. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator-= (const T2 &value)
 Subtracts value from each element. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator*= (const T2 &value)
 Multiplies each element. More...
 
template<std::convertible_to< value_type > T2>
constexpr Vectoroperator/= (const T2 &value)
 Divides each element. More...
 
template<std::convertible_to< value_type > T2>
requires modable<T>
constexpr Vectoroperator%= (const T2 &rawValue)
 Applies modulo on each element. More...
 
constexpr auto begin () noexcept
 Returns an iterator to the first element. More...
 
constexpr auto begin () const noexcept
 Returns an const iterator to the first element. More...
 
constexpr auto cbegin () const noexcept
 Returns an const iterator to the first element. More...
 
constexpr auto end () noexcept
 Returns an iterator to the end (i.e. the element after the last element). More...
 
constexpr auto end () const noexcept
 Returns an const iterator to the end (i.e. the element after the last element). More...
 
constexpr auto cend () const noexcept
 Returns an const iterator to the end (i.e. the element after the last element). More...
 
constexpr auto rbegin () noexcept
 Returns an iterator to the reverse-beginning. More...
 
constexpr auto rbegin () const noexcept
 Returns an const iterator to the reverse-beginning. More...
 
constexpr auto crbegin () const noexcept
 Returns an const iterator to the reverse-beginning. More...
 
constexpr auto rend () noexcept
 Returns an iterator to the reverse-end of the given range (i.e. the element before the first element). More...
 
constexpr auto rend () const noexcept
 Returns an const iterator to the reverse-end of the given range (i.e. the element before the first element). More...
 
constexpr auto crend () const noexcept
 Returns an const iterator to the reverse-end of the given range (i.e. the element before the first element). More...
 

Static Public Attributes

static constexpr std::size_t dimensions { VDimensions }
 Dimension amount as constant. More...
 

Detailed Description

template<value_type T, std::size_t VDimensions>
requires (0 < VDimensions)
class sl::vec::Vector< T, VDimensions >

A mathematically vector implementation.

Template Parameters
TThe value type
VDimensionsAmount of dimensions. Must be implicitly convertible to std::size_t.

Member Typedef Documentation

◆ storage_type

template<value_type T, std::size_t VDimensions>
using sl::vec::Vector< T, VDimensions >::storage_type = std::array<value_type, dimensions>

Used storage type.

◆ value_type

template<value_type T, std::size_t VDimensions>
using sl::vec::Vector< T, VDimensions >::value_type = std::remove_cvref_t<T>

Alias for T, but without modifiers.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<value_type T, std::size_t VDimensions>
constexpr sl::vec::Vector< T, VDimensions >::Vector ( )
constexprdefaultnoexcept

Default constructor.

Default initializes all elements via uniform initialization, thus all arithmetic types will defaulted to 0.

◆ ~Vector()

template<value_type T, std::size_t VDimensions>
constexpr sl::vec::Vector< T, VDimensions >::~Vector ( )
constexprdefaultnoexcept

Default destructor.

◆ Vector() [2/4]

template<value_type T, std::size_t VDimensions>
constexpr sl::vec::Vector< T, VDimensions >::Vector ( const Vector< T, VDimensions > &  )
constexprdefaultnoexcept

Default copy-constructor.

◆ Vector() [3/4]

template<value_type T, std::size_t VDimensions>
constexpr sl::vec::Vector< T, VDimensions >::Vector ( Vector< T, VDimensions > &&  )
constexprdefaultnoexcept

Default move-constructor.

◆ Vector() [4/4]

template<value_type T, std::size_t VDimensions>
template<class... TArgs>
requires std::convertible_to<std::invoke_result_t<TGenerator&>, value_type>
VDimensions<=1) constexpr Vector(TArgs &&...args) noexcept :m_Values{ static_cast< T >(args)... } { } template< std::convertible_to< value_type > T2, auto VOtherDimensions > requires(!std::same_as< T2, value_type >||dimensions !=VOtherDimensions) constexpr explicit Vector(const Vector< T2, VOtherDimensions > &other) { transform_unseq( std::ranges::take_view{ other, std::min(dimensions, VOtherDimensions) }, std::ranges::begin(m_Values), fn::cast_invoke_result< value_type >(std::identity{})); } template< std::invocable TGenerator > constexpr sl::vec::Vector< T, VDimensions >::Vector ( TGenerator  generator)
inlineexplicitconstexpr

Aggregate initialization like constructor.

Template Parameters
TArgsVariadic types used for initialization.
Parameters
argsArguments from which the storage will be initialized.

This constructor directly initializes the internal storage with the given arguments. The amount of args must be equal to the amount of dimensions.

Member Function Documentation

◆ begin() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::begin ( ) const
inlineconstexprnoexcept

Returns an const iterator to the first element.

Returns
An const iterator to the first element.

◆ begin() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::begin ( )
inlineconstexprnoexcept

Returns an iterator to the first element.

Returns
An iterator to the first element.

◆ cbegin()

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::cbegin ( ) const
inlineconstexprnoexcept

Returns an const iterator to the first element.

Returns
An const iterator to the first element.

◆ cend()

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::cend ( ) const
inlineconstexprnoexcept

Returns an const iterator to the end (i.e. the element after the last element).

Returns
An const iterator to the end of the element range. Note that the end of a range is defined as the element following the last valid element.

◆ crbegin()

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::crbegin ( ) const
inlineconstexprnoexcept

Returns an const iterator to the reverse-beginning.

Returns
An const iterator to the reverse-beginning.

◆ crend()

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::crend ( ) const
inlineconstexprnoexcept

Returns an const iterator to the reverse-end of the given range (i.e. the element before the first element).

Returns
An const iterator to the reverse-end of the given range. Note that the reverse-end of a range is defined as the element previous to the first valid element.

◆ end() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::end ( ) const
inlineconstexprnoexcept

Returns an const iterator to the end (i.e. the element after the last element).

Returns
An iterator to the end of the element range. Note that the end of a range is defined as the element following the last valid element.

◆ end() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::end ( )
inlineconstexprnoexcept

Returns an iterator to the end (i.e. the element after the last element).

Returns
An iterator to the end of the element range. Note that the end of a range is defined as the element following the last valid element.

◆ operator%=()

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
requires modable<T>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator%= ( const T2 &  rawValue)
inlineconstexpr

Applies modulo on each element.

Template Parameters
T2Must be convertible to value_type
Parameters
rawValueValue which will be modulo applied
Returns
reference to this
Remarks
Division by 0 is undefined.

◆ operator*=()

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator*= ( const T2 &  value)
inlineconstexpr

Multiplies each element.

Template Parameters
T2Must be convertible to value_type
Parameters
valueValue each element will be multiplied by
Returns
reference to this

◆ operator+=() [1/2]

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator+= ( const T2 &  value)
inlineconstexpr

Adds value to each element.

Template Parameters
T2Must be convertible to value_type
Parameters
valueValue to be added
Returns
reference to this

◆ operator+=() [2/2]

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator+= ( const Vector< T2, dimensions > &  other)
inlineconstexpr

Adds other Vector element-wise.

Template Parameters
T2T of other Vector
Parameters
otherother Vector
Returns
reference to this

◆ operator-=() [1/2]

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator-= ( const T2 &  value)
inlineconstexpr

Subtracts value from each element.

Template Parameters
T2Must be convertible to value_type
Parameters
valueValue to be subtracted
Returns
reference to this

◆ operator-=() [2/2]

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator-= ( const Vector< T2, dimensions > &  other)
inlineconstexpr

Subtracts other Vector element-wise.

Template Parameters
T2T of other Vector
Parameters
otherother Vector
Returns
reference to this

◆ operator/=()

template<value_type T, std::size_t VDimensions>
template<std::convertible_to< value_type > T2>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator/= ( const T2 &  value)
inlineconstexpr

Divides each element.

Template Parameters
T2Must be convertible to value_type
Parameters
valueValue each element will be divided by
Returns
reference to this
Remarks
Division by 0 is undefined.

◆ operator=() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator= ( const Vector< T, VDimensions > &  )
constexprdefaultnoexcept

Default copy-assign-operator.

Returns
reference to this

◆ operator=() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr Vector & sl::vec::Vector< T, VDimensions >::operator= ( Vector< T, VDimensions > &&  )
constexprdefaultnoexcept

Default move-assign-operator.

Returns
reference to this

◆ operator==()

template<value_type T, std::size_t VDimensions>
constexpr bool sl::vec::Vector< T, VDimensions >::operator== ( const Vector< T, VDimensions > &  ) const
constexprdefaultnoexcept

Default equality comparison operator.

Returns
true if both Vectors are treated as equal.

This does automatically enable the operator !=.

◆ operator[]() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr const value_type & sl::vec::Vector< T, VDimensions >::operator[] ( std::integral auto  index) const
inlineconstexprnoexcept

Accesses a specific element.

Parameters
indexIndex of the element.
Returns
const reference to the element
Remarks
Using index less than zero or greater-equal than dimensions, is undefined.

◆ operator[]() [2/2]

template<value_type T, std::size_t VDimensions>
template<std::integral TIndex>
constexpr value_type & sl::vec::Vector< T, VDimensions >::operator[] ( std::integral auto  index)
inlineconstexprnoexcept

Accesses a specific element.

Parameters
indexIndex of the element.
Returns
const reference to the element
Remarks
Using index less than zero or greater-equal than dimensions, is undefined.

◆ rbegin() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::rbegin ( ) const
inlineconstexprnoexcept

Returns an const iterator to the reverse-beginning.

Returns
An const iterator to the reverse-beginning.

◆ rbegin() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::rbegin ( )
inlineconstexprnoexcept

Returns an iterator to the reverse-beginning.

Returns
An iterator to the reverse-beginning.

◆ rend() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::rend ( ) const
inlineconstexprnoexcept

Returns an const iterator to the reverse-end of the given range (i.e. the element before the first element).

Returns
An const iterator to the reverse-end of the given range. Note that the reverse-end of a range is defined as the element previous to the first valid element.

◆ rend() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr auto sl::vec::Vector< T, VDimensions >::rend ( )
inlineconstexprnoexcept

Returns an iterator to the reverse-end of the given range (i.e. the element before the first element).

Returns
An iterator to the reverse-end of the given range. Note that the reverse-end of a range is defined as the element previous to the first valid element.

◆ x() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr const value_type & sl::vec::Vector< T, VDimensions >::x ( ) const
inlineconstexprnoexcept

Accesses the first element.

Returns
const reference to the first element

◆ x() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr value_type & sl::vec::Vector< T, VDimensions >::x ( )
inlineconstexprnoexcept

Accesses the first element.

Returns
reference to the first element

◆ y() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr const value_type & sl::vec::Vector< T, VDimensions >::y ( ) const
inlineconstexprnoexcept

Accesses the second element.

Returns
const reference to the second element
Remarks
This functions is only available, if Vector has 2 or more dimension.

◆ y() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr value_type & sl::vec::Vector< T, VDimensions >::y ( )
inlineconstexprnoexcept

Accesses the second element.

Returns
reference to the second element
Remarks
This functions is only available, if Vector has 2 or more dimension.

◆ z() [1/2]

template<value_type T, std::size_t VDimensions>
constexpr const value_type & sl::vec::Vector< T, VDimensions >::z ( ) const
inlineconstexprnoexcept

Accesses the third element.

Returns
const reference to the third element
Remarks
This functions is only available, if Vector has 3 or more dimension.

◆ z() [2/2]

template<value_type T, std::size_t VDimensions>
constexpr value_type & sl::vec::Vector< T, VDimensions >::z ( )
inlineconstexprnoexcept

Accesses the third element.

Returns
reference to the third element
Remarks
This functions is only available, if Vector has 3 or more dimension.

Member Data Documentation

◆ dimensions

template<value_type T, std::size_t VDimensions>
constexpr std::size_t sl::vec::Vector< T, VDimensions >::dimensions { VDimensions }
staticconstexpr

Dimension amount as constant.


The documentation for this class was generated from the following file: