Chemical Data Processing Library C++ API - Version 1.4.0
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
CDPL::Math::CVector< T, N > Class Template Reference

Fixed-size vector of dimension N backed by a C-array (no dynamic allocation). More...

#include <Vector.hpp>

+ Inheritance diagram for CDPL::Math::CVector< T, N >:

Public Types

typedef T ValueType
 The scalar value type. More...
 
typedef T & Reference
 Mutable reference type to an element. More...
 
typedef const T & ConstReference
 Constant reference type to an element. More...
 
typedef std::size_t SizeType
 The unsigned size type. More...
 
typedef std::ptrdiff_t DifferenceType
 The signed difference type. More...
 
typedef ValueType ArrayType[N]
 The fixed-size C-array type used for in-memory storage of N elements. More...
 
typedef T * Pointer
 Pointer type for raw access to the element array. More...
 
typedef const T * ConstPointer
 Constant pointer type for raw access to the element array. More...
 
typedef VectorReference< SelfTypeClosureType
 Closure type used when this vector appears inside another expression. More...
 
typedef const VectorReference< const SelfTypeConstClosureType
 Constant closure type used when this vector appears inside another expression. More...
 
typedef BoundedVector< T, N+1 > VectorTemporaryType
 Concrete temporary vector type used by expression-template machinery (a Math::BoundedVector of N + 1 capacity). More...
 
typedef std::shared_ptr< SelfTypeSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated CVector instances. More...
 
typedef std::initializer_list< T > InitializerListType
 The initializer-list type accepted by constructors and assignment. More...
 
- Public Types inherited from CDPL::Math::VectorContainer< CVector< T, N > >
typedef CVector< T, N > ContainerType
 The derived vector container type. More...
 
- Public Types inherited from CDPL::Math::VectorExpression< E >
typedef E ExpressionType
 The derived vector expression type. More...
 
- Public Types inherited from CDPL::Math::Expression< E >
typedef E ExpressionType
 The derived expression type (made available to expression-template machinery). More...
 

Public Member Functions

 CVector ()
 Constructs a zero-initialized N-element vector. More...
 
 CVector (const ValueType &v)
 Constructs an N-element vector with every element initialized to v. More...
 
 CVector (const CVector &v)
 Constructs a copy of the fixed-size vector v. More...
 
 CVector (InitializerListType l)
 Constructs a fixed-size vector with the contents of the initializer list l. More...
 
template<typename E >
 CVector (const VectorExpression< E > &e)
 Constructs a fixed-size vector from the vector expression e. More...
 
Reference operator[] (SizeType i)
 Returns a mutable reference to the element at index i (alias for operator()). More...
 
ConstReference operator[] (SizeType i) const
 Returns a const reference to the element at index i (alias for operator()). More...
 
Reference operator() (SizeType i)
 Returns a mutable reference to the element at index i. More...
 
ConstReference operator() (SizeType i) const
 Returns a const reference to the element at index i. More...
 
bool isEmpty () const
 Tells whether the vector is empty (N is zero). More...
 
SizeType getSize () const
 Returns the fixed element count N. More...
 
SizeType getMaxSize () const
 Returns the fixed element count N (capacity equals size for Math::CVector). More...
 
Pointer getData ()
 Returns a mutable pointer to the contiguous element array. More...
 
ConstPointer getData () const
 Returns a const pointer to the contiguous element array. More...
 
CVectoroperator= (const CVector &v)
 Copy-assigns the elements of v to this fixed-size vector. More...
 
CVectoroperator= (InitializerListType l)
 Assigns the contents of the initializer list l to this fixed-size vector. More...
 
template<typename C >
CVectoroperator= (const VectorContainer< C > &c)
 Assigns the contents of the vector container c to this fixed-size vector (no alias check needed). More...
 
template<typename E >
CVectoroperator= (const VectorExpression< E > &e)
 Assigns the vector expression e to this fixed-size vector (via a temporary to handle aliasing). More...
 
template<typename C >
CVectoroperator+= (const VectorContainer< C > &c)
 Adds the contents of the vector container c element-wise to this fixed-size vector (no alias check needed). More...
 
CVectoroperator+= (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this fixed-size vector. More...
 
template<typename E >
CVectoroperator+= (const VectorExpression< E > &e)
 Adds the vector expression e element-wise to this fixed-size vector (via a temporary to handle aliasing). More...
 
template<typename C >
CVectoroperator-= (const VectorContainer< C > &c)
 Subtracts the contents of the vector container c element-wise from this fixed-size vector (no alias check needed). More...
 
CVectoroperator-= (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this fixed-size vector. More...
 
template<typename E >
CVectoroperator-= (const VectorExpression< E > &e)
 Subtracts the vector expression e element-wise from this fixed-size vector (via a temporary to handle aliasing). More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, CVector >::type & operator*= (const T1 &t)
 Multiplies every element by the scalar t. More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, CVector >::type & operator/= (const T1 &t)
 Divides every element by the scalar t. More...
 
template<typename E >
CVectorassign (const VectorExpression< E > &e)
 Assigns the elements of the vector expression e to this fixed-size vector without intermediate temporary. More...
 
CVectorassign (InitializerListType l)
 Assigns the contents of the initializer list l to this fixed-size vector (truncated to N if longer; zero-padded if shorter). More...
 
template<typename E >
CVectorplusAssign (const VectorExpression< E > &e)
 Adds the elements of the vector expression e to this vector without intermediate temporary. More...
 
CVectorplusAssign (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this vector without intermediate temporary. More...
 
template<typename E >
CVectorminusAssign (const VectorExpression< E > &e)
 Subtracts the elements of the vector expression e from this vector without intermediate temporary. More...
 
CVectorminusAssign (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this vector without intermediate temporary. More...
 
void swap (CVector &v)
 Swaps the contents of this fixed-size vector with those of v. More...
 
void clear (const ValueType &v=ValueType())
 Sets every element of the vector to the value v. More...
 
- Public Member Functions inherited from CDPL::Math::VectorContainer< CVector< T, N > >
const ContainerTypeoperator() () const
 Returns a const reference to the derived vector container. More...
 
ContainerTypeoperator() ()
 Returns a reference to the derived vector container. More...
 
- Public Member Functions inherited from CDPL::Math::VectorExpression< E >
const ExpressionTypeoperator() () const
 Returns a const reference to the derived vector expression. More...
 
ExpressionTypeoperator() ()
 Returns a reference to the derived vector expression. More...
 

Static Public Attributes

static const SizeType Size = N
 The compile-time fixed size N. More...
 

Friends

void swap (CVector &v1, CVector &v2)
 ADL-enabled free-function form of swap(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from CDPL::Math::VectorContainer< CVector< T, N > >
 VectorContainer ()
 
 ~VectorContainer ()
 
- Protected Member Functions inherited from CDPL::Math::VectorExpression< E >
 VectorExpression ()
 
 ~VectorExpression ()
 
- Protected Member Functions inherited from CDPL::Math::Expression< E >
 Expression ()
 
 ~Expression ()
 

Detailed Description

template<typename T, std::size_t N>
class CDPL::Math::CVector< T, N >

Fixed-size vector of dimension N backed by a C-array (no dynamic allocation).

Template Parameters
TThe scalar value type.
NThe vector dimension.

Member Typedef Documentation

◆ ValueType

template<typename T , std::size_t N>
typedef T CDPL::Math::CVector< T, N >::ValueType

The scalar value type.

◆ Reference

template<typename T , std::size_t N>
typedef T& CDPL::Math::CVector< T, N >::Reference

Mutable reference type to an element.

◆ ConstReference

template<typename T , std::size_t N>
typedef const T& CDPL::Math::CVector< T, N >::ConstReference

Constant reference type to an element.

◆ SizeType

template<typename T , std::size_t N>
typedef std::size_t CDPL::Math::CVector< T, N >::SizeType

The unsigned size type.

◆ DifferenceType

template<typename T , std::size_t N>
typedef std::ptrdiff_t CDPL::Math::CVector< T, N >::DifferenceType

The signed difference type.

◆ ArrayType

template<typename T , std::size_t N>
typedef ValueType CDPL::Math::CVector< T, N >::ArrayType[N]

The fixed-size C-array type used for in-memory storage of N elements.

◆ Pointer

template<typename T , std::size_t N>
typedef T* CDPL::Math::CVector< T, N >::Pointer

Pointer type for raw access to the element array.

◆ ConstPointer

template<typename T , std::size_t N>
typedef const T* CDPL::Math::CVector< T, N >::ConstPointer

Constant pointer type for raw access to the element array.

◆ ClosureType

template<typename T , std::size_t N>
typedef VectorReference<SelfType> CDPL::Math::CVector< T, N >::ClosureType

Closure type used when this vector appears inside another expression.

◆ ConstClosureType

template<typename T , std::size_t N>
typedef const VectorReference<const SelfType> CDPL::Math::CVector< T, N >::ConstClosureType

Constant closure type used when this vector appears inside another expression.

◆ VectorTemporaryType

template<typename T , std::size_t N>
typedef BoundedVector<T, N + 1> CDPL::Math::CVector< T, N >::VectorTemporaryType

Concrete temporary vector type used by expression-template machinery (a Math::BoundedVector of N + 1 capacity).

◆ SharedPointer

template<typename T , std::size_t N>
typedef std::shared_ptr<SelfType> CDPL::Math::CVector< T, N >::SharedPointer

A reference-counted smart pointer [SHPTR] for dynamically allocated CVector instances.

◆ InitializerListType

template<typename T , std::size_t N>
typedef std::initializer_list<T> CDPL::Math::CVector< T, N >::InitializerListType

The initializer-list type accepted by constructors and assignment.

Constructor & Destructor Documentation

◆ CVector() [1/5]

template<typename T , std::size_t N>
CDPL::Math::CVector< T, N >::CVector ( )
inline

Constructs a zero-initialized N-element vector.

◆ CVector() [2/5]

template<typename T , std::size_t N>
CDPL::Math::CVector< T, N >::CVector ( const ValueType v)
inlineexplicit

Constructs an N-element vector with every element initialized to v.

Parameters
vThe initial element value.

◆ CVector() [3/5]

template<typename T , std::size_t N>
CDPL::Math::CVector< T, N >::CVector ( const CVector< T, N > &  v)
inline

Constructs a copy of the fixed-size vector v.

Parameters
vThe fixed-size vector to copy.

◆ CVector() [4/5]

template<typename T , std::size_t N>
CDPL::Math::CVector< T, N >::CVector ( InitializerListType  l)
inline

Constructs a fixed-size vector with the contents of the initializer list l.

Parameters
lThe initializer list providing the initial elements (truncated to N if longer; zero-padded if shorter).

◆ CVector() [5/5]

template<typename T , std::size_t N>
template<typename E >
CDPL::Math::CVector< T, N >::CVector ( const VectorExpression< E > &  e)
inline

Constructs a fixed-size vector from the vector expression e.

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T , std::size_t N>
Reference CDPL::Math::CVector< T, N >::operator[] ( SizeType  i)
inline

Returns a mutable reference to the element at index i (alias for operator()).

Parameters
iThe zero-based element index.
Returns
A mutable reference to the element.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator[]() [2/2]

template<typename T , std::size_t N>
ConstReference CDPL::Math::CVector< T, N >::operator[] ( SizeType  i) const
inline

Returns a const reference to the element at index i (alias for operator()).

Parameters
iThe zero-based element index.
Returns
A const reference to the element.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator()() [1/2]

template<typename T , std::size_t N>
Reference CDPL::Math::CVector< T, N >::operator() ( SizeType  i)
inline

Returns a mutable reference to the element at index i.

Parameters
iThe zero-based element index.
Returns
A mutable reference to the element.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator()() [2/2]

template<typename T , std::size_t N>
ConstReference CDPL::Math::CVector< T, N >::operator() ( SizeType  i) const
inline

Returns a const reference to the element at index i.

Parameters
iThe zero-based element index.
Returns
A const reference to the element.
Exceptions
Base::IndexErrorif i is out of range.

◆ isEmpty()

template<typename T , std::size_t N>
bool CDPL::Math::CVector< T, N >::isEmpty ( ) const
inline

Tells whether the vector is empty (N is zero).

Returns
true if N is zero, and false otherwise.

◆ getSize()

template<typename T , std::size_t N>
SizeType CDPL::Math::CVector< T, N >::getSize ( ) const
inline

Returns the fixed element count N.

Returns
The element count.

◆ getMaxSize()

template<typename T , std::size_t N>
SizeType CDPL::Math::CVector< T, N >::getMaxSize ( ) const
inline

Returns the fixed element count N (capacity equals size for Math::CVector).

Returns
The element count.

◆ getData() [1/2]

template<typename T , std::size_t N>
Pointer CDPL::Math::CVector< T, N >::getData ( )
inline

Returns a mutable pointer to the contiguous element array.

Returns
A mutable pointer to the element array.

◆ getData() [2/2]

template<typename T , std::size_t N>
ConstPointer CDPL::Math::CVector< T, N >::getData ( ) const
inline

Returns a const pointer to the contiguous element array.

Returns
A const pointer to the element array.

◆ operator=() [1/4]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::operator= ( const CVector< T, N > &  v)
inline

Copy-assigns the elements of v to this fixed-size vector.

Parameters
vThe source fixed-size vector.
Returns
A reference to itself.

◆ operator=() [2/4]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::operator= ( InitializerListType  l)
inline

Assigns the contents of the initializer list l to this fixed-size vector.

Parameters
lThe initializer list providing the new elements (truncated to N if longer; zero-padded if shorter).
Returns
A reference to itself.

◆ operator=() [3/4]

template<typename T , std::size_t N>
template<typename C >
CVector& CDPL::Math::CVector< T, N >::operator= ( const VectorContainer< C > &  c)
inline

Assigns the contents of the vector container c to this fixed-size vector (no alias check needed).

Template Parameters
CThe source vector container type.
Parameters
cThe source vector container.
Returns
A reference to itself.

◆ operator=() [4/4]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::operator= ( const VectorExpression< E > &  e)
inline

Assigns the vector expression e to this fixed-size vector (via a temporary to handle aliasing).

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ operator+=() [1/3]

template<typename T , std::size_t N>
template<typename C >
CVector& CDPL::Math::CVector< T, N >::operator+= ( const VectorContainer< C > &  c)
inline

Adds the contents of the vector container c element-wise to this fixed-size vector (no alias check needed).

Template Parameters
CThe source vector container type.
Parameters
cThe source vector container.
Returns
A reference to itself.

◆ operator+=() [2/3]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::operator+= ( InitializerListType  l)
inline

Adds the contents of the initializer list l element-wise to this fixed-size vector.

Parameters
lThe initializer list providing the addends.
Returns
A reference to itself.

◆ operator+=() [3/3]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::operator+= ( const VectorExpression< E > &  e)
inline

Adds the vector expression e element-wise to this fixed-size vector (via a temporary to handle aliasing).

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ operator-=() [1/3]

template<typename T , std::size_t N>
template<typename C >
CVector& CDPL::Math::CVector< T, N >::operator-= ( const VectorContainer< C > &  c)
inline

Subtracts the contents of the vector container c element-wise from this fixed-size vector (no alias check needed).

Template Parameters
CThe source vector container type.
Parameters
cThe source vector container.
Returns
A reference to itself.

◆ operator-=() [2/3]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::operator-= ( InitializerListType  l)
inline

Subtracts the contents of the initializer list l element-wise from this fixed-size vector.

Parameters
lThe initializer list providing the subtrahends.
Returns
A reference to itself.

◆ operator-=() [3/3]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::operator-= ( const VectorExpression< E > &  e)
inline

Subtracts the vector expression e element-wise from this fixed-size vector (via a temporary to handle aliasing).

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ operator*=()

template<typename T , std::size_t N>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, CVector>::type& CDPL::Math::CVector< T, N >::operator*= ( const T1 &  t)
inline

Multiplies every element by the scalar t.

Template Parameters
T1The scalar type.
Parameters
tThe scalar multiplier.
Returns
A reference to itself.

◆ operator/=()

template<typename T , std::size_t N>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, CVector>::type& CDPL::Math::CVector< T, N >::operator/= ( const T1 &  t)
inline

Divides every element by the scalar t.

Template Parameters
T1The scalar type.
Parameters
tThe scalar divisor.
Returns
A reference to itself.

◆ assign() [1/2]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::assign ( const VectorExpression< E > &  e)
inline

Assigns the elements of the vector expression e to this fixed-size vector without intermediate temporary.

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ assign() [2/2]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::assign ( InitializerListType  l)
inline

Assigns the contents of the initializer list l to this fixed-size vector (truncated to N if longer; zero-padded if shorter).

Parameters
lThe initializer list providing the new elements.
Returns
A reference to itself.
Exceptions
Base::SizeErrorif l.size() exceeds N.

◆ plusAssign() [1/2]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::plusAssign ( const VectorExpression< E > &  e)
inline

Adds the elements of the vector expression e to this vector without intermediate temporary.

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ plusAssign() [2/2]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::plusAssign ( InitializerListType  l)
inline

Adds the contents of the initializer list l element-wise to this vector without intermediate temporary.

Parameters
lThe initializer list providing the addends.
Returns
A reference to itself.

◆ minusAssign() [1/2]

template<typename T , std::size_t N>
template<typename E >
CVector& CDPL::Math::CVector< T, N >::minusAssign ( const VectorExpression< E > &  e)
inline

Subtracts the elements of the vector expression e from this vector without intermediate temporary.

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Returns
A reference to itself.

◆ minusAssign() [2/2]

template<typename T , std::size_t N>
CVector& CDPL::Math::CVector< T, N >::minusAssign ( InitializerListType  l)
inline

Subtracts the contents of the initializer list l element-wise from this vector without intermediate temporary.

Parameters
lThe initializer list providing the subtrahends.
Returns
A reference to itself.

◆ swap()

template<typename T , std::size_t N>
void CDPL::Math::CVector< T, N >::swap ( CVector< T, N > &  v)
inline

Swaps the contents of this fixed-size vector with those of v.

Parameters
vThe fixed-size vector to swap with.

◆ clear()

template<typename T , std::size_t N>
void CDPL::Math::CVector< T, N >::clear ( const ValueType v = ValueType())
inline

Sets every element of the vector to the value v.

Parameters
vThe fill value.

Friends And Related Function Documentation

◆ swap

template<typename T , std::size_t N>
void swap ( CVector< T, N > &  v1,
CVector< T, N > &  v2 
)
friend

ADL-enabled free-function form of swap().

Parameters
v1The first fixed-size vector.
v2The second fixed-size vector.

Member Data Documentation

◆ Size

template<typename T , std::size_t N>
const CVector< T, N >::SizeType CDPL::Math::CVector< T, N >::Size = N
static

The compile-time fixed size N.


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