CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Vector< T, N > Class Template Reference

Algebraic vector. More...

#include <cc/Vector>

Public Types

using Item = T
 Item type.
 

Static Public Attributes

static constexpr int Count = N
 Number of components.
 

Standard Iterators

using value_type = Item
 Item value type.
 
using size_type = long
 Type of the container capacity.
 
using iterator = ArrayIterator<Vector, 1>
 Value iterator.
 
using const_iterator = ArrayIterator<const Vector, 1>
 Readonly value iterator.
 
using reverse_iterator = ArrayIterator<Vector, -1>
 Reverse value iterator.
 
using const_reverse_iterator = ArrayIterator<const Vector, -1>
 Readonly reverse value iterator.
 
iterator begin ()
 Return iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 

Construction and Assignment

 Vector ()
 Create a null vector.
 
 Vector (std::initializer_list< T > l)
 Create a vector with initial components l.
 
 Vector (T b)
 Create a vector with all components initialized with b.
 

Item Access

T & at (int i)
 Get reference to component at i.
 
const T & at (int i) const
 Get constant reference to component at i.
 
T & operator[] (int i)
 Get reference to component at i.
 
const T & operator[] (int i) const
 Get constant reference to component at i.
 
x () const
 Get value of the first component.
 
y () const
 Get value of the second component.
 
z () const
 Get value of the third component.
 
static constexpr int count ()
 Get the number of components.
 

Global Operations

Vector operator- () const
 Negate all components of the vector.
 
Vectoroperator+= (const Vector &b)
 Add component-vise vector b.
 
Vectoroperator-= (const Vector &b)
 Substract component-vise vector b.
 
Vectoroperator*= (const Vector &b)
 Multiply component-vise vector b.
 
Vectoroperator/= (const Vector &b)
 Divide component-vise vector b.
 
Vectoroperator*= (T b)
 Multiply each component with b.
 
Vectoroperator/= (T b)
 Divide each component with b.
 
Vector operator+ (const Vector &b) const
 Add vector b and return result.
 
Vector operator- (const Vector &b) const
 Substract vector b and return result.
 
Vector operator* (const Vector &b) const
 Component-wise multiply vector b and return result.
 
Vector operator/ (const Vector &b) const
 Component-wise divide vector b and return result.
 
Vector operator* (T b) const
 Multiply each component with b and return result.
 
Vector operator/ (T b) const
 Divide each component with b and return result.
 
Vector round () const
 Get a copy of this vector with each component rounded.
 
Vector ceil () const
 Get a copy of this vector with each component rounded upwards.
 
min () const
 Get the smallest component value.
 
max () const
 Get the greatest component value.
 
absPow2 () const
 Magnitude squared.
 
abs () const
 Magnitude.
 
avg () const
 Compute the average of all component values.
 

Comparism Operators

bool operator== (const Vector &b) const
 Equal to operator.
 
std::strong_ordering operator<=> (const Vector &b) const
 Ordering operator.
 

Detailed Description

template<class T, int N>
class cc::Vector< T, N >

Algebraic vector.

Template Parameters
TItem type
NNumber of components

Member Typedef Documentation

◆ Item

template<class T , int N>
using Item = T

Item type.

◆ value_type

template<class T , int N>
using value_type = Item

Item value type.

◆ size_type

template<class T , int N>
using size_type = long

Type of the container capacity.

◆ iterator

template<class T , int N>
using iterator = ArrayIterator<Vector, 1>

Value iterator.

◆ const_iterator

template<class T , int N>
using const_iterator = ArrayIterator<const Vector, 1>

Readonly value iterator.

◆ reverse_iterator

template<class T , int N>
using reverse_iterator = ArrayIterator<Vector, -1>

Reverse value iterator.

◆ const_reverse_iterator

template<class T , int N>
using const_reverse_iterator = ArrayIterator<const Vector, -1>

Readonly reverse value iterator.

Constructor & Destructor Documentation

◆ Vector() [1/3]

template<class T , int N>
Vector ( )

Create a null vector.

◆ Vector() [2/3]

template<class T , int N>
Vector ( std::initializer_list< T > l)

Create a vector with initial components l.

◆ Vector() [3/3]

template<class T , int N>
Vector ( T b)

Create a vector with all components initialized with b.

Member Function Documentation

◆ count()

template<class T , int N>
static constexpr int count ( )
staticconstexpr

Get the number of components.

◆ at() [1/2]

template<class T , int N>
T & at ( int i)

Get reference to component at i.

◆ at() [2/2]

template<class T , int N>
const T & at ( int i) const

Get constant reference to component at i.

◆ operator[]() [1/2]

template<class T , int N>
T & operator[] ( int i)

Get reference to component at i.

◆ operator[]() [2/2]

template<class T , int N>
const T & operator[] ( int i) const

Get constant reference to component at i.

◆ x()

template<class T , int N>
T x ( ) const

Get value of the first component.

◆ y()

template<class T , int N>
T y ( ) const

Get value of the second component.

◆ z()

template<class T , int N>
T z ( ) const

Get value of the third component.

◆ operator-() [1/2]

template<class T , int N>
Vector operator- ( ) const

Negate all components of the vector.

◆ operator+=()

template<class T , int N>
Vector & operator+= ( const Vector< T, N > & b)

Add component-vise vector b.

◆ operator-=()

template<class T , int N>
Vector & operator-= ( const Vector< T, N > & b)

Substract component-vise vector b.

◆ operator*=() [1/2]

template<class T , int N>
Vector & operator*= ( const Vector< T, N > & b)

Multiply component-vise vector b.

◆ operator/=() [1/2]

template<class T , int N>
Vector & operator/= ( const Vector< T, N > & b)

Divide component-vise vector b.

◆ operator*=() [2/2]

template<class T , int N>
Vector & operator*= ( T b)

Multiply each component with b.

◆ operator/=() [2/2]

template<class T , int N>
Vector & operator/= ( T b)

Divide each component with b.

◆ operator+()

template<class T , int N>
Vector operator+ ( const Vector< T, N > & b) const

Add vector b and return result.

◆ operator-() [2/2]

template<class T , int N>
Vector operator- ( const Vector< T, N > & b) const

Substract vector b and return result.

◆ operator*() [1/2]

template<class T , int N>
Vector operator* ( const Vector< T, N > & b) const

Component-wise multiply vector b and return result.

◆ operator/() [1/2]

template<class T , int N>
Vector operator/ ( const Vector< T, N > & b) const

Component-wise divide vector b and return result.

◆ operator*() [2/2]

template<class T , int N>
Vector operator* ( T b) const

Multiply each component with b and return result.

◆ operator/() [2/2]

template<class T , int N>
Vector operator/ ( T b) const

Divide each component with b and return result.

◆ round()

template<class T , int N>
Vector round ( ) const

Get a copy of this vector with each component rounded.

◆ ceil()

template<class T , int N>
Vector ceil ( ) const

Get a copy of this vector with each component rounded upwards.

◆ min()

template<class T , int N>
T min ( ) const

Get the smallest component value.

◆ max()

template<class T , int N>
T max ( ) const

Get the greatest component value.

◆ absPow2()

template<class T , int N>
T absPow2 ( ) const

Magnitude squared.

◆ abs()

template<class T , int N>
T abs ( ) const

Magnitude.

◆ avg()

template<class T , int N>
T avg ( ) const

Compute the average of all component values.

◆ begin() [1/2]

template<class T , int N>
iterator begin ( )

Return iterator pointing to the first item (if any)

◆ end() [1/2]

template<class T , int N>
iterator end ( )

Return iterator pointing behind the last item

◆ begin() [2/2]

template<class T , int N>
const_iterator begin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ cbegin()

template<class T , int N>
const_iterator cbegin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ end() [2/2]

template<class T , int N>
const_iterator end ( ) const

Return readonly iterator pointing behind the last item

◆ cend()

template<class T , int N>
const_iterator cend ( ) const

Return readonly iterator pointing behind the last item

◆ rbegin() [1/2]

template<class T , int N>
reverse_iterator rbegin ( )

Return reverse iterator pointing to the last item (if any)

◆ rend() [1/2]

template<class T , int N>
reverse_iterator rend ( )

Return reverse iterator pointing before the first item

◆ rbegin() [2/2]

template<class T , int N>
const_reverse_iterator rbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ crbegin()

template<class T , int N>
const_reverse_iterator crbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ rend() [2/2]

template<class T , int N>
const_reverse_iterator rend ( ) const

Return reverse iterator pointing before the first item

◆ crend()

template<class T , int N>
const_reverse_iterator crend ( ) const

Return reverse iterator pointing before the first item

◆ operator==()

template<class T , int N>
bool operator== ( const Vector< T, N > & b) const

Equal to operator.

◆ operator<=>()

template<class T , int N>
std::strong_ordering operator<=> ( const Vector< T, N > & b) const

Ordering operator.

Member Data Documentation

◆ Count

template<class T , int N>
constexpr int Count = N
staticconstexpr

Number of components.