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

Dynamically-sized dense vector with configurable underlying storage. More...

#include <Vector.hpp>

+ Inheritance diagram for CDPL::Math::Vector< T, A >:

Public Types

typedef T ValueType
 The scalar value type stored in the vector. More...
 
typedef T & Reference
 Mutable reference type to an element. More...
 
typedef const T & ConstReference
 Constant reference type to an element. More...
 
typedef A::size_type SizeType
 The unsigned size type used by the underlying storage container. More...
 
typedef A::difference_type DifferenceType
 The signed difference type used by the underlying storage container. More...
 
typedef A ArrayType
 The underlying storage container type. More...
 
typedef T * Pointer
 Pointer type for raw element access. More...
 
typedef const T * ConstPointer
 Constant pointer type for raw element access. 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 SelfType VectorTemporaryType
 Concrete temporary vector type used by expression-template machinery. More...
 
typedef std::shared_ptr< SelfTypeSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated Vector instances. More...
 
typedef std::initializer_list< T > InitializerListType
 Type of the brace-initializer list accepted by the corresponding constructor. More...
 
- Public Types inherited from CDPL::Math::VectorContainer< Vector< T, std::vector< T > > >
typedef Vector< T, std::vector< T > > 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

 Vector ()
 Constructs an empty vector (size zero). More...
 
 Vector (SizeType n)
 Constructs a vector of size n with default-initialized elements. More...
 
 Vector (SizeType n, const ValueType &v)
 Constructs a vector of size n with every element initialized to v. More...
 
 Vector (const ArrayType &data)
 Constructs a vector that copies its data directly from the underlying-array container data. More...
 
 Vector (const Vector &v)
 Constructs a copy of the vector v. More...
 
 Vector (Vector &&v)
 Move-constructs a vector from v (v is left in a valid empty state). More...
 
 Vector (InitializerListType l)
 Constructs the vector from a brace-initializer list l. More...
 
template<typename E >
 Vector (const VectorExpression< E > &e)
 Constructs the vector from the vector expression e (materializing the expression result). 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. More...
 
SizeType getSize () const
 Returns the current element count. More...
 
SizeType getMaxSize () const
 Returns the maximum number of elements the underlying storage container can hold. More...
 
ArrayTypegetData ()
 Returns a mutable reference to the underlying storage container. More...
 
const ArrayTypegetData () const
 Returns a const reference to the underlying storage container. More...
 
Vectoroperator= (const Vector &v)
 Copy-assigns the elements of v to this vector. More...
 
Vectoroperator= (Vector &&v)
 Move-assigns the elements of v to this vector. More...
 
Vectoroperator= (InitializerListType l)
 Assigns the contents of the initializer list l to this vector (resizes to fit). More...
 
template<typename C >
Vectoroperator= (const VectorContainer< C > &c)
 Assigns the contents of the vector container c to this vector (no alias check needed). More...
 
template<typename E >
Vectoroperator= (const VectorExpression< E > &e)
 Assigns the vector expression e to this vector (via a temporary to handle aliasing). More...
 
template<typename C >
Vectoroperator+= (const VectorContainer< C > &c)
 Adds the contents of the vector container c element-wise to this vector (no alias check needed). More...
 
Vectoroperator+= (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this vector. More...
 
template<typename E >
Vectoroperator+= (const VectorExpression< E > &e)
 Adds the vector expression e element-wise to this vector (via a temporary to handle aliasing). More...
 
template<typename C >
Vectoroperator-= (const VectorContainer< C > &c)
 Subtracts the contents of the vector container c element-wise from this vector (no alias check needed). More...
 
Vectoroperator-= (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this vector. More...
 
template<typename E >
Vectoroperator-= (const VectorExpression< E > &e)
 Subtracts the vector expression e element-wise from this vector (via a temporary to handle aliasing). More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, Vector >::type & operator*= (const T1 &t)
 Multiplies every element by the scalar t. More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, Vector >::type & operator/= (const T1 &t)
 Divides every element by the scalar t. More...
 
template<typename E >
Vectorassign (const VectorExpression< E > &e)
 Resizes this vector to match e and assigns the elements of e without intermediate temporary. More...
 
Vectorassign (InitializerListType l)
 Assigns the contents of the initializer list l to this vector. More...
 
template<typename E >
VectorplusAssign (const VectorExpression< E > &e)
 Adds the elements of the vector expression e to this vector without intermediate temporary. More...
 
VectorplusAssign (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this vector without intermediate temporary. More...
 
template<typename E >
VectorminusAssign (const VectorExpression< E > &e)
 Subtracts the elements of the vector expression e from this vector without intermediate temporary. More...
 
VectorminusAssign (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this vector without intermediate temporary. More...
 
void swap (Vector &v)
 Swaps the contents of this vector with those of v. More...
 
void clear (const ValueType &v=ValueType())
 Sets every element of the vector to the value v. More...
 
void resize (SizeType n, const ValueType &v=ValueType())
 Resizes the vector to n elements. More...
 
- Public Member Functions inherited from CDPL::Math::VectorContainer< Vector< T, std::vector< T > > >
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...
 

Friends

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

Additional Inherited Members

- Protected Member Functions inherited from CDPL::Math::VectorContainer< Vector< T, std::vector< T > > >
 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, typename A = std::vector<T>>
class CDPL::Math::Vector< T, A >

Dynamically-sized dense vector with configurable underlying storage.

Template Parameters
TThe scalar value type.
AThe underlying storage container type (default: std::vector).

Member Typedef Documentation

◆ ValueType

template<typename T , typename A = std::vector<T>>
typedef T CDPL::Math::Vector< T, A >::ValueType

The scalar value type stored in the vector.

◆ Reference

template<typename T , typename A = std::vector<T>>
typedef T& CDPL::Math::Vector< T, A >::Reference

Mutable reference type to an element.

◆ ConstReference

template<typename T , typename A = std::vector<T>>
typedef const T& CDPL::Math::Vector< T, A >::ConstReference

Constant reference type to an element.

◆ SizeType

template<typename T , typename A = std::vector<T>>
typedef A::size_type CDPL::Math::Vector< T, A >::SizeType

The unsigned size type used by the underlying storage container.

◆ DifferenceType

template<typename T , typename A = std::vector<T>>
typedef A::difference_type CDPL::Math::Vector< T, A >::DifferenceType

The signed difference type used by the underlying storage container.

◆ ArrayType

template<typename T , typename A = std::vector<T>>
typedef A CDPL::Math::Vector< T, A >::ArrayType

The underlying storage container type.

◆ Pointer

template<typename T , typename A = std::vector<T>>
typedef T* CDPL::Math::Vector< T, A >::Pointer

Pointer type for raw element access.

◆ ConstPointer

template<typename T , typename A = std::vector<T>>
typedef const T* CDPL::Math::Vector< T, A >::ConstPointer

Constant pointer type for raw element access.

◆ ClosureType

template<typename T , typename A = std::vector<T>>
typedef VectorReference<SelfType> CDPL::Math::Vector< T, A >::ClosureType

Closure type used when this vector appears inside another expression.

◆ ConstClosureType

template<typename T , typename A = std::vector<T>>
typedef const VectorReference<const SelfType> CDPL::Math::Vector< T, A >::ConstClosureType

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

◆ VectorTemporaryType

template<typename T , typename A = std::vector<T>>
typedef SelfType CDPL::Math::Vector< T, A >::VectorTemporaryType

Concrete temporary vector type used by expression-template machinery.

◆ SharedPointer

template<typename T , typename A = std::vector<T>>
typedef std::shared_ptr<SelfType> CDPL::Math::Vector< T, A >::SharedPointer

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

◆ InitializerListType

template<typename T , typename A = std::vector<T>>
typedef std::initializer_list<T> CDPL::Math::Vector< T, A >::InitializerListType

Type of the brace-initializer list accepted by the corresponding constructor.

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( )
inline

Constructs an empty vector (size zero).

◆ Vector() [2/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( SizeType  n)
inlineexplicit

Constructs a vector of size n with default-initialized elements.

Parameters
nThe desired vector size.

◆ Vector() [3/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( SizeType  n,
const ValueType v 
)
inline

Constructs a vector of size n with every element initialized to v.

Parameters
nThe desired vector size.
vThe element value used to initialize every entry.

◆ Vector() [4/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( const ArrayType data)
inline

Constructs a vector that copies its data directly from the underlying-array container data.

Parameters
dataThe source storage container.

◆ Vector() [5/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( const Vector< T, A > &  v)
inline

Constructs a copy of the vector v.

Parameters
vThe vector to copy.

◆ Vector() [6/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( Vector< T, A > &&  v)
inline

Move-constructs a vector from v (v is left in a valid empty state).

Parameters
vThe vector to move from.

◆ Vector() [7/8]

template<typename T , typename A = std::vector<T>>
CDPL::Math::Vector< T, A >::Vector ( InitializerListType  l)
inline

Constructs the vector from a brace-initializer list l.

Parameters
lThe initializer list (one element per vector entry).

◆ Vector() [8/8]

template<typename T , typename A = std::vector<T>>
template<typename E >
CDPL::Math::Vector< T, A >::Vector ( const VectorExpression< E > &  e)
inline

Constructs the vector from the vector expression e (materializing the expression result).

Template Parameters
EThe vector expression type.
Parameters
eThe vector expression to materialize.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T , typename A = std::vector<T>>
Reference CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
ConstReference CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
Reference CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
ConstReference CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
bool CDPL::Math::Vector< T, A >::isEmpty ( ) const
inline

Tells whether the vector is empty.

Returns
true if the vector contains no elements, and false otherwise.

◆ getSize()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Vector< T, A >::getSize ( ) const
inline

Returns the current element count.

Returns
The number of elements.

◆ getMaxSize()

template<typename T , typename A = std::vector<T>>
SizeType CDPL::Math::Vector< T, A >::getMaxSize ( ) const
inline

Returns the maximum number of elements the underlying storage container can hold.

Returns
The maximum element count.

◆ getData() [1/2]

template<typename T , typename A = std::vector<T>>
ArrayType& CDPL::Math::Vector< T, A >::getData ( )
inline

Returns a mutable reference to the underlying storage container.

Returns
A mutable reference to the storage container.

◆ getData() [2/2]

template<typename T , typename A = std::vector<T>>
const ArrayType& CDPL::Math::Vector< T, A >::getData ( ) const
inline

Returns a const reference to the underlying storage container.

Returns
A const reference to the storage container.

◆ operator=() [1/5]

template<typename T , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::operator= ( const Vector< T, A > &  v)
inline

Copy-assigns the elements of v to this vector.

Parameters
vThe source vector.
Returns
A reference to itself.

◆ operator=() [2/5]

template<typename T , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::operator= ( Vector< T, A > &&  v)
inline

Move-assigns the elements of v to this vector.

Parameters
vThe source vector (left in a valid but unspecified state).
Returns
A reference to itself.

◆ operator=() [3/5]

template<typename T , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::operator= ( InitializerListType  l)
inline

Assigns the contents of the initializer list l to this vector (resizes to fit).

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

◆ operator=() [4/5]

template<typename T , typename A = std::vector<T>>
template<typename C >
Vector& CDPL::Math::Vector< T, A >::operator= ( const VectorContainer< C > &  c)
inline

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

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

◆ operator=() [5/5]

template<typename T , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::operator= ( const VectorExpression< E > &  e)
inline

Assigns the vector expression e to this 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 , typename A = std::vector<T>>
template<typename C >
Vector& CDPL::Math::Vector< T, A >::operator+= ( const VectorContainer< C > &  c)
inline

Adds the contents of the vector container c element-wise to this 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 , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::operator+= ( InitializerListType  l)
inline

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

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

◆ operator+=() [3/3]

template<typename T , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::operator+= ( const VectorExpression< E > &  e)
inline

Adds the vector expression e element-wise to this 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 , typename A = std::vector<T>>
template<typename C >
Vector& CDPL::Math::Vector< T, A >::operator-= ( const VectorContainer< C > &  c)
inline

Subtracts the contents of the vector container c element-wise from this 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 , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::operator-= ( InitializerListType  l)
inline

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

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

◆ operator-=() [3/3]

template<typename T , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::operator-= ( const VectorExpression< E > &  e)
inline

Subtracts the vector expression e element-wise from this 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 , typename A = std::vector<T>>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, Vector>::type& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
template<typename T1 >
std::enable_if<IsScalar<T1>::value, Vector>::type& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::assign ( const VectorExpression< E > &  e)
inline

Resizes this vector to match e and assigns the elements of e 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 , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::assign ( InitializerListType  l)
inline

Assigns the contents of the initializer list l to this vector.

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

◆ plusAssign() [1/2]

template<typename T , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
template<typename E >
Vector& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
Vector& CDPL::Math::Vector< T, A >::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 , typename A = std::vector<T>>
void CDPL::Math::Vector< T, A >::swap ( Vector< T, A > &  v)
inline

Swaps the contents of this vector with those of v.

Parameters
vThe vector to swap with.

◆ clear()

template<typename T , typename A = std::vector<T>>
void CDPL::Math::Vector< T, A >::clear ( const ValueType v = ValueType())
inline

Sets every element of the vector to the value v.

Parameters
vThe fill value.

◆ resize()

template<typename T , typename A = std::vector<T>>
void CDPL::Math::Vector< T, A >::resize ( SizeType  n,
const ValueType v = ValueType() 
)
inline

Resizes the vector to n elements.

Parameters
nThe new element count.
vThe fill value for newly added elements.

Friends And Related Function Documentation

◆ swap

template<typename T , typename A = std::vector<T>>
void swap ( Vector< T, A > &  v1,
Vector< T, A > &  v2 
)
friend

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

Parameters
v1The first vector.
v2The second vector.

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