PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::Vector< T, N > Struct Template Reference

Vector. More...

#include <Vector.hpp>

Inheritance diagram for playrho::Vector< T, N >:
[legend]
Collaboration diagram for playrho::Vector< T, N >:
[legend]

Public Types

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

Public Member Functions

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

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>
constexpr Vector< T, N > abs (const Vector< T, N > &v) noexcept
 Absolute value function for vectors.
 
template<typename T , std::size_t N>
constexpr bool operator== (const Vector< T, N > &lhs, const Vector< T, N > &rhs) noexcept
 Equality operator.
 
template<typename T , std::size_t N>
constexpr bool operator!= (const Vector< T, N > &lhs, const Vector< T, N > &rhs) noexcept
 Inequality operator.
 
template<typename T , std::size_t N>
constexpr std::enable_if_t< std::is_same< T, decltype(+T{})>::value, Vector< T, N > > operator+ (Vector< T, N > v) noexcept
 Unary plus operator.
 
template<typename T , std::size_t N>
constexpr std::enable_if_t< std::is_same< T, decltype(-T{})>::value, Vector< T, N > > operator- (Vector< T, N > v) noexcept
 Unary negation operator.
 
template<typename T , std::size_t N>
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.
 
template<typename T , std::size_t N>
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.
 
template<typename T , std::size_t N>
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.
 
template<typename T , std::size_t N>
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.
 
template<typename T1 , typename T2 , std::size_t N>
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.
 
template<typename T1 , typename T2 , std::size_t N>
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.
 
template<typename T1 , typename T2 , std::size_t A, std::size_t B, std::size_t C, typename OT = decltype(T1{} * T2{})>
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{})>
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{})>
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{})>
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.
 
template<std::size_t I, std::size_t N, typename T >
constexpr auto & get (Vector< T, N > &v) noexcept
 Gets the specified element of the given collection.
 
template<typename T , std::size_t N>
std::ostream & operator<< (::std::ostream &os, const Vector< T, N > &value)
 Output stream operator.
 

Detailed Description

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

Vector.

This is a constexpr 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, DistanceJoint.cpp, FrictionJoint.cpp, GearJoint.cpp, HelloWorld.cpp, Joint.cpp, MotorJoint.cpp, PrismaticJoint.cpp, PulleyJoint.cpp, RevoluteJoint.cpp, RopeJoint.cpp, Shape.cpp, TargetJoint.cpp, WeldJoint.cpp, WheelJoint.cpp, World.cpp, WorldBody.cpp, and WorldFixture.cpp.

Constructor & Destructor Documentation

◆ Vector()

template<typename T , std::size_t N>
constexpr playrho::Vector< T, N >::Vector ( )
constexprdefault

Default constructor.

Note
Defaulted explicitly.
This constructor performs no action.

Member Function Documentation

◆ at() [1/2]

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

Gets a reference to the requested element.

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

◆ at() [2/2]

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

Gets a constant reference to the requested element.

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

◆ empty()

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

Whether empty.

Note
Always false for N > 0.

◆ operator[]() [1/2]

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

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().

◆ operator[]() [2/2]

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

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().

Friends And Related Function Documentation

◆ operator*() [1/3]

template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
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".

◆ operator*() [2/3]

template<typename T1 , typename T2 , std::size_t A, std::size_t B, std::size_t C, typename OT = decltype(T1{} * T2{})>
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

◆ operator*() [3/3]

template<std::size_t N, typename T1 , typename T2 , typename OT = decltype(T1{} * T2{})>
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".

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.

Referenced by playrho::Vector< Real >::at(), playrho::Vector< Real >::begin(), playrho::Vector< Real >::crbegin(), playrho::Vector< Real >::crend(), playrho::Vector< Real >::data(), playrho::Vector< Real >::end(), playrho::Vector< Real >::operator[](), playrho::Vector< Real >::rbegin(), and playrho::Vector< Real >::rend().


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