playrho::Vector< T, N > Struct Template Reference

Vector. More...

#include <Vector.hpp>

Public Types

using value_type = T
 Value type. More...
 
using size_type = std::size_t
 Size type. More...
 
using difference_type = std::ptrdiff_t
 Difference type. More...
 
using reference = value_type &
 Reference type. More...
 
using const_reference = const value_type &
 Constant reference type. More...
 
using pointer = value_type *
 Pointer type. More...
 
using const_pointer = const value_type *
 Constant pointer type. More...
 
using iterator = value_type *
 Iterator type. More...
 
using const_iterator = const value_type *
 Constant iterator type. More...
 
using reverse_iterator = std::reverse_iterator< iterator >
 Reverse iterator type. More...
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 Constant reverse iterator type. More...
 

Public Member Functions

PLAYRHO_CONSTEXPR Vector ()=default
 Default constructor. More...
 
template<typename... Tail>
PLAYRHO_CONSTEXPR Vector (std::enable_if_t< sizeof...(Tail)+1==N, T > head, Tail... tail) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR size_type max_size () const noexcept
 Gets the max size. More...
 
PLAYRHO_CONSTEXPR size_type size () const noexcept
 Gets the size. More...
 
PLAYRHO_CONSTEXPR bool empty () const noexcept
 Whether empty. More...
 
iterator begin () noexcept
 Gets a "begin" iterator. More...
 
iterator end () noexcept
 Gets an "end" iterator. More...
 
const_iterator begin () const noexcept
 Gets a "begin" iterator. More...
 
const_iterator end () const noexcept
 Gets an "end" iterator. More...
 
const_iterator cbegin () const noexcept
 Gets a "begin" iterator. More...
 
const_iterator cend () const noexcept
 Gets an "end" iterator. More...
 
reverse_iterator rbegin () noexcept
 Gets a reverse "begin" iterator. More...
 
reverse_iterator rend () noexcept
 Gets a reverse "end" iterator. More...
 
const_reverse_iterator crbegin () const noexcept
 Gets a reverse "begin" iterator. More...
 
const_reverse_iterator crend () const noexcept
 Gets a reverse "end" iterator. More...
 
const_reverse_iterator rbegin () const noexcept
 Gets a reverse "begin" iterator. More...
 
const_reverse_iterator rend () const noexcept
 Gets a reverse "end" iterator. More...
 
PLAYRHO_CONSTEXPR reference operator[] (size_type pos) noexcept
 Gets a reference to the requested element. More...
 
PLAYRHO_CONSTEXPR const_reference operator[] (size_type pos) const noexcept
 Gets a constant reference to the requested element. More...
 
PLAYRHO_CONSTEXPR reference at (size_type pos)
 Gets a reference to the requested element. More...
 
PLAYRHO_CONSTEXPR const_reference at (size_type pos) const
 Gets a constant reference to the requested element. More...
 
PLAYRHO_CONSTEXPR pointer data () noexcept
 Direct access to data. More...
 
PLAYRHO_CONSTEXPR const_pointer data () const noexcept
 Direct access to data. More...
 

Public Attributes

value_type elements [N? N:1]
 Elements. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR Vector< T, N > abs (const Vector< T, N > &v) noexcept
 Absolute value function for vectors. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR bool operator== (const Vector< T, N > &lhs, const Vector< T, N > &rhs) noexcept
 Equality operator. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR bool operator!= (const Vector< T, N > &lhs, const Vector< T, N > &rhs) noexcept
 Inequality operator. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(+T{})>::value, Vector< T, N > > operator+ (Vector< T, N > v) noexcept
 Unary plus operator. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(-T{})>::value, Vector< T, N > > operator- (Vector< T, N > v) noexcept
 Unary negation operator. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{}+T{})>::value, Vector< T, N > & > operator+= (Vector< T, N > &lhs, const Vector< T, N > rhs) noexcept
 Increments the left hand side value by the right hand side value. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{} - T{})>::value, Vector< T, N > & > operator-= (Vector< T, N > &lhs, const Vector< T, N > rhs) noexcept
 Decrements the left hand side value by the right hand side value. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{}+T{})>::value, Vector< T, N > > operator+ (Vector< T, N > lhs, const Vector< T, N > rhs) noexcept
 Adds two vectors component-wise. More...
 
template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{} - T{})>::value, Vector< T, N > > operator- (Vector< T, N > lhs, const Vector< T, N > rhs) noexcept
 Subtracts two vectors component-wise. More...
 
template<typename T1 , typename T2 , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T1, decltype(T1{} *T2{})>::value, Vector< T1, N > & > operator*= (Vector< T1, N > &lhs, const T2 rhs) noexcept
 Multiplication assignment operator. More...
 
template<typename T1 , typename T2 , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T1, decltype(T1{}/T2{})>::value, Vector< T1, N > & > operator/= (Vector< T1, N > &lhs, const T2 rhs) noexcept
 Division assignment operator. More...
 
template<typename T1 , typename T2 , std::size_t A, std::size_t B, std::size_t C, typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value, Vector< Vector< OT, C >, A > > operator* (const Vector< Vector< T1, B >, A > &lhs, const Vector< Vector< T2, C >, B > &rhs) noexcept
 Calculates the matrix product of the two given vector of vectors (matrices). More...
 
template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value &&!IsVector< T1 >::value, Vector< OT, N > > operator* (const T1 s, Vector< T2, N > a) noexcept
 Multiplication operator for non-vector times vector. More...
 
template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value &&!IsVector< T2 >::value, Vector< OT, N > > operator* (Vector< T1, N > a, const T2 s) noexcept
 Multiplication operator for vector times non-vector. More...
 
template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} / T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsDivisable< T1, T2 >::value &&!IsVector< T2 >::value, Vector< OT, N > > operator/ (Vector< T1, N > a, const T2 s) noexcept
 Division operator. More...
 
template<std::size_t I, std::size_t N, typename T >
PLAYRHO_CONSTEXPR auto & get (Vector< T, N > &v) noexcept
 Gets the specified element of the given collection. More...
 
template<typename T , std::size_t N>
std::ostream & operator<< (::std::ostream &os, const Vector< T, N > &value)
 Output stream operator. More...
 

Detailed Description

template<typename T, std::size_t N>
struct playrho::Vector< T, N >

Vector.

This is a PLAYRHO_CONSTEXPR inline and constructor enhanced std::array-like template class for types supporting the +, -, *, / arithmetic operators ("arithmetic types" as defined by the IsArithmetic type trait) that itself comes with non-member arithmetic operator support making Vector instances arithmetic types as well.

Note
This type is trivially default constructible - i.e. default construction performs no actions (no initialization).
See also
IsArithmetic, Vector Traits
Examples
Body.cpp, HelloWorld.cpp, and World.cpp.

Definition at line 48 of file Vector.hpp.

Member Typedef Documentation

◆ value_type

template<typename T , std::size_t N>
using playrho::Vector< T, N >::value_type = T

Value type.

Definition at line 51 of file Vector.hpp.

◆ size_type

template<typename T , std::size_t N>
using playrho::Vector< T, N >::size_type = std::size_t

Size type.

Definition at line 54 of file Vector.hpp.

◆ difference_type

template<typename T , std::size_t N>
using playrho::Vector< T, N >::difference_type = std::ptrdiff_t

Difference type.

Definition at line 57 of file Vector.hpp.

◆ reference

template<typename T , std::size_t N>
using playrho::Vector< T, N >::reference = value_type&

Reference type.

Definition at line 60 of file Vector.hpp.

◆ const_reference

template<typename T , std::size_t N>
using playrho::Vector< T, N >::const_reference = const value_type&

Constant reference type.

Definition at line 63 of file Vector.hpp.

◆ pointer

template<typename T , std::size_t N>
using playrho::Vector< T, N >::pointer = value_type*

Pointer type.

Definition at line 66 of file Vector.hpp.

◆ const_pointer

template<typename T , std::size_t N>
using playrho::Vector< T, N >::const_pointer = const value_type*

Constant pointer type.

Definition at line 69 of file Vector.hpp.

◆ iterator

template<typename T , std::size_t N>
using playrho::Vector< T, N >::iterator = value_type*

Iterator type.

Definition at line 72 of file Vector.hpp.

◆ const_iterator

template<typename T , std::size_t N>
using playrho::Vector< T, N >::const_iterator = const value_type*

Constant iterator type.

Definition at line 75 of file Vector.hpp.

◆ reverse_iterator

template<typename T , std::size_t N>
using playrho::Vector< T, N >::reverse_iterator = std::reverse_iterator<iterator>

Reverse iterator type.

Definition at line 78 of file Vector.hpp.

◆ const_reverse_iterator

template<typename T , std::size_t N>
using playrho::Vector< T, N >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Constant reverse iterator type.

Definition at line 81 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR playrho::Vector< T, N >::Vector ( )
inlinedefault

Default constructor.

Note
Defaulted explicitly.
This constructor performs no action.

◆ Vector() [2/2]

template<typename T , std::size_t N>
template<typename... Tail>
PLAYRHO_CONSTEXPR playrho::Vector< T, N >::Vector ( std::enable_if_t< sizeof...(Tail)+1==N, T >  head,
Tail...  tail 
)
inlinenoexcept

Initializing constructor.

Definition at line 90 of file Vector.hpp.

Member Function Documentation

◆ max_size()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR size_type playrho::Vector< T, N >::max_size ( ) const
inlinenoexcept

Gets the max size.

Definition at line 97 of file Vector.hpp.

◆ size()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR size_type playrho::Vector< T, N >::size ( ) const
inlinenoexcept

Gets the size.

Definition at line 100 of file Vector.hpp.

◆ empty()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR bool playrho::Vector< T, N >::empty ( ) const
inlinenoexcept

Whether empty.

Note
Always false for N > 0.

Definition at line 104 of file Vector.hpp.

◆ begin() [1/2]

template<typename T , std::size_t N>
iterator playrho::Vector< T, N >::begin ( )
inlinenoexcept

Gets a "begin" iterator.

Definition at line 107 of file Vector.hpp.

◆ end() [1/2]

template<typename T , std::size_t N>
iterator playrho::Vector< T, N >::end ( )
inlinenoexcept

Gets an "end" iterator.

Definition at line 110 of file Vector.hpp.

◆ begin() [2/2]

template<typename T , std::size_t N>
const_iterator playrho::Vector< T, N >::begin ( ) const
inlinenoexcept

Gets a "begin" iterator.

Definition at line 113 of file Vector.hpp.

◆ end() [2/2]

template<typename T , std::size_t N>
const_iterator playrho::Vector< T, N >::end ( ) const
inlinenoexcept

Gets an "end" iterator.

Definition at line 116 of file Vector.hpp.

◆ cbegin()

template<typename T , std::size_t N>
const_iterator playrho::Vector< T, N >::cbegin ( ) const
inlinenoexcept

Gets a "begin" iterator.

Definition at line 119 of file Vector.hpp.

◆ cend()

template<typename T , std::size_t N>
const_iterator playrho::Vector< T, N >::cend ( ) const
inlinenoexcept

Gets an "end" iterator.

Definition at line 122 of file Vector.hpp.

◆ rbegin() [1/2]

template<typename T , std::size_t N>
reverse_iterator playrho::Vector< T, N >::rbegin ( )
inlinenoexcept

Gets a reverse "begin" iterator.

Definition at line 125 of file Vector.hpp.

◆ rend() [1/2]

template<typename T , std::size_t N>
reverse_iterator playrho::Vector< T, N >::rend ( )
inlinenoexcept

Gets a reverse "end" iterator.

Definition at line 128 of file Vector.hpp.

◆ crbegin()

template<typename T , std::size_t N>
const_reverse_iterator playrho::Vector< T, N >::crbegin ( ) const
inlinenoexcept

Gets a reverse "begin" iterator.

Definition at line 131 of file Vector.hpp.

◆ crend()

template<typename T , std::size_t N>
const_reverse_iterator playrho::Vector< T, N >::crend ( ) const
inlinenoexcept

Gets a reverse "end" iterator.

Definition at line 137 of file Vector.hpp.

◆ rbegin() [2/2]

template<typename T , std::size_t N>
const_reverse_iterator playrho::Vector< T, N >::rbegin ( ) const
inlinenoexcept

Gets a reverse "begin" iterator.

Definition at line 143 of file Vector.hpp.

◆ rend() [2/2]

template<typename T , std::size_t N>
const_reverse_iterator playrho::Vector< T, N >::rend ( ) const
inlinenoexcept

Gets a reverse "end" iterator.

Definition at line 149 of file Vector.hpp.

◆ operator[]() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR reference playrho::Vector< T, N >::operator[] ( size_type  pos)
inlinenoexcept

Gets a reference to the requested element.

Note
No bounds checking is performed.
Warning
Behavior is undefined if given a position equal to or greater than size().

Definition at line 157 of file Vector.hpp.

◆ operator[]() [2/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR const_reference playrho::Vector< T, N >::operator[] ( size_type  pos) const
inlinenoexcept

Gets a constant reference to the requested element.

Note
No bounds checking is performed.
Warning
Behavior is undefined if given a position equal to or greater than size().

Definition at line 166 of file Vector.hpp.

◆ at() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR reference playrho::Vector< T, N >::at ( size_type  pos)
inline

Gets a reference to the requested element.

Exceptions
InvalidArgumentif given a position that's >= size().

Definition at line 174 of file Vector.hpp.

◆ at() [2/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR const_reference playrho::Vector< T, N >::at ( size_type  pos) const
inline

Gets a constant reference to the requested element.

Exceptions
InvalidArgumentif given a position that's >= size().

Definition at line 185 of file Vector.hpp.

◆ data() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR pointer playrho::Vector< T, N >::data ( )
inlinenoexcept

Direct access to data.

Definition at line 195 of file Vector.hpp.

◆ data() [2/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR const_pointer playrho::Vector< T, N >::data ( ) const
inlinenoexcept

Direct access to data.

Definition at line 201 of file Vector.hpp.

Friends And Related Function Documentation

◆ operator==()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR bool operator== ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Equality operator.

Definition at line 245 of file Vector.hpp.

◆ operator!=()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR bool operator!= ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Inequality operator.

Definition at line 260 of file Vector.hpp.

◆ operator+() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(+T{})>::value, Vector< T, N > > operator+ ( Vector< T, N >  v)
related

Unary plus operator.

Definition at line 270 of file Vector.hpp.

◆ operator-() [1/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(-T{})>::value, Vector< T, N > > operator- ( Vector< T, N >  v)
related

Unary negation operator.

Definition at line 280 of file Vector.hpp.

◆ operator+=()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{}+T{})>::value, Vector< T, N > & > operator+= ( Vector< T, N > &  lhs,
const Vector< T, N >  rhs 
)
related

Increments the left hand side value by the right hand side value.

Definition at line 294 of file Vector.hpp.

◆ operator-=()

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{} - T{})>::value, Vector< T, N > & > operator-= ( Vector< T, N > &  lhs,
const Vector< T, N >  rhs 
)
related

Decrements the left hand side value by the right hand side value.

Definition at line 308 of file Vector.hpp.

◆ operator+() [2/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{}+T{})>::value, Vector< T, N > > operator+ ( Vector< T, N >  lhs,
const Vector< T, N >  rhs 
)
related

Adds two vectors component-wise.

Definition at line 322 of file Vector.hpp.

◆ operator-() [2/2]

template<typename T , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T, decltype(T{} - T{})>::value, Vector< T, N > > operator- ( Vector< T, N >  lhs,
const Vector< T, N >  rhs 
)
related

Subtracts two vectors component-wise.

Definition at line 332 of file Vector.hpp.

◆ operator*=()

template<typename T1 , typename T2 , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T1, decltype(T1{} *T2{})>::value, Vector< T1, N > & > operator*= ( Vector< T1, N > &  lhs,
const T2  rhs 
)
related

Multiplication assignment operator.

Definition at line 342 of file Vector.hpp.

◆ operator/=()

template<typename T1 , typename T2 , std::size_t N>
PLAYRHO_CONSTEXPR std::enable_if_t< std::is_same< T1, decltype(T1{}/T2{})>::value, Vector< T1, N > & > operator/= ( Vector< T1, N > &  lhs,
const T2  rhs 
)
related

Division assignment operator.

Definition at line 356 of file Vector.hpp.

◆ operator*() [1/3]

template<typename T1 , typename T2 , std::size_t A, std::size_t B, std::size_t C, typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value, Vector< Vector< OT, C >, A > > operator* ( const Vector< Vector< T1, B >, A > &  lhs,
const Vector< Vector< T2, C >, B > &  rhs 
)
related

Calculates the matrix product of the two given vector of vectors (matrices).

Multiplies an A-by-B vector of vectors by a B-by-C vector of vectors returning an A-by-C vector of vectors.

Note
From Wikipedia:

Multiplication of two matrices is defined if and only if the number of columns of the left matrix is the same as the number of rows of the right matrix.

Matrix multiplication is not commutative.
Algorithmically speaking, this implementation is called the "naive" algorithm. For small matrices, like 3-by-3 or smaller matrices, its complexity shouldn't be an issue. The matrix dimensions are compile time constants anyway which can help compilers automatically identify loop unrolling and hardware level parallelism opportunities.
Parameters
lhsLeft-hand-side matrix.
rhsRight-hand-side matrix.
Returns
A-by-C matrix product of the left-hand-side matrix and the right-hand-side matrix.
See also
https://en.wikipedia.org/wiki/Matrix_multiplication
https://en.wikipedia.org/wiki/Matrix_multiplication_algorithm
https://en.wikipedia.org/wiki/Commutative_property

Definition at line 388 of file Vector.hpp.

◆ operator*() [2/3]

template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value &&!IsVector< T1 >::value, Vector< OT, N > > operator* ( const T1  s,
Vector< T2, N >  a 
)
related

Multiplication operator for non-vector times vector.

Note
Explicitly disabled for Vector * Vector to prevent this function from existing in that case and prevent errors like "use of overloaded operator '*' is ambiguous".

Definition at line 472 of file Vector.hpp.

◆ operator*() [3/3]

template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsMultipliable< T1, T2 >::value &&!IsVector< T2 >::value, Vector< OT, N > > operator* ( Vector< T1, N >  a,
const T2  s 
)
related

Multiplication operator for vector times non-vector.

Note
Explicitly disabled for Vector * Vector to prevent this function from existing in that case and prevent errors like "use of overloaded operator '*' is ambiguous".

Definition at line 490 of file Vector.hpp.

◆ operator/()

template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} / T2{})>
PLAYRHO_CONSTEXPR std::enable_if_t< IsDivisable< T1, T2 >::value &&!IsVector< T2 >::value, Vector< OT, N > > operator/ ( Vector< T1, N >  a,
const T2  s 
)
related

Division operator.

Definition at line 506 of file Vector.hpp.

◆ get()

template<std::size_t I, std::size_t N, typename T >
PLAYRHO_CONSTEXPR auto & get ( Vector< T, N > &  v)
related

Gets the specified element of the given collection.

Definition at line 521 of file Vector.hpp.

◆ operator<<()

template<typename T , std::size_t N>
std::ostream & operator<< ( ::std::ostream &  os,
const Vector< T, N > &  value 
)
related

Output stream operator.

Definition at line 538 of file Vector.hpp.

Member Data Documentation

◆ elements

template<typename T , std::size_t N>
value_type playrho::Vector< T, N >::elements[N? N:1]

Elements.

Array of N elements unless N is 0 in which case this is an array of 1 element.

Warning
Don't access this directly!
Data is not initialized on default construction. This is intentional to avoid any performance overhead that default initialization might incur.

Definition at line 211 of file Vector.hpp.


The documentation for this struct was generated from the following files: