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::BoundedVector< T, N > Class Template Reference

Variable-size vector with a fixed upper capacity N stored in a stack-allocated array. More...

#include <Vector.hpp>

+ Inheritance diagram for CDPL::Math::BoundedVector< 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-capacity C-array type used for in-memory storage. 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 (one element larger than the bound). More...
 
typedef std::shared_ptr< SelfTypeSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated BoundedVector 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< BoundedVector< T, N > >
typedef BoundedVector< 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

 BoundedVector ()
 Constructs an empty bounded vector (size zero, capacity N). More...
 
 BoundedVector (SizeType n)
 Constructs a bounded vector of size n with value-initialized elements. More...
 
 BoundedVector (SizeType n, const ValueType &v)
 Constructs a bounded vector of size n with every element initialized to v. More...
 
 BoundedVector (const BoundedVector &v)
 Constructs a copy of the bounded vector v. More...
 
 BoundedVector (InitializerListType l)
 Constructs a bounded vector with the contents of the initializer list l. More...
 
template<typename E >
 BoundedVector (const VectorExpression< E > &e)
 Constructs a bounded 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. More...
 
SizeType getSize () const
 Returns the current element count. More...
 
SizeType getMaxSize () const
 Returns the compile-time maximum capacity N. 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...
 
BoundedVectoroperator= (const BoundedVector &v)
 Copy-assigns the elements of v to this bounded vector. More...
 
BoundedVectoroperator= (InitializerListType l)
 Assigns the contents of the initializer list l to this bounded vector. More...
 
template<typename C >
BoundedVectoroperator= (const VectorContainer< C > &c)
 Assigns the contents of the vector container c to this bounded vector (no alias check needed). More...
 
template<typename E >
BoundedVectoroperator= (const VectorExpression< E > &e)
 Assigns the vector expression e to this bounded vector (via a temporary to handle aliasing). More...
 
template<typename C >
BoundedVectoroperator+= (const VectorContainer< C > &c)
 Adds the contents of the vector container c element-wise to this bounded vector (no alias check needed). More...
 
BoundedVectoroperator+= (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this bounded vector. More...
 
template<typename E >
BoundedVectoroperator+= (const VectorExpression< E > &e)
 Adds the vector expression e element-wise to this bounded vector (via a temporary to handle aliasing). More...
 
template<typename C >
BoundedVectoroperator-= (const VectorContainer< C > &c)
 Subtracts the contents of the vector container c element-wise from this bounded vector (no alias check needed). More...
 
BoundedVectoroperator-= (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this bounded vector. More...
 
template<typename E >
BoundedVectoroperator-= (const VectorExpression< E > &e)
 Subtracts the vector expression e element-wise from this bounded vector (via a temporary to handle aliasing). More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, BoundedVector >::type & operator*= (const T1 &t)
 Multiplies every element by the scalar t. More...
 
template<typename T1 >
std::enable_if< IsScalar< T1 >::value, BoundedVector >::type & operator/= (const T1 &t)
 Divides every element by the scalar t. More...
 
template<typename E >
BoundedVectorassign (const VectorExpression< E > &e)
 Resizes this vector to match e and assigns the elements of e without intermediate temporary. More...
 
BoundedVectorassign (InitializerListType l)
 Resizes this vector to match l and copies the elements of l in. More...
 
template<typename E >
BoundedVectorplusAssign (const VectorExpression< E > &e)
 Adds the elements of the vector expression e to this vector without intermediate temporary. More...
 
BoundedVectorplusAssign (InitializerListType l)
 Adds the contents of the initializer list l element-wise to this vector without intermediate temporary. More...
 
template<typename E >
BoundedVectorminusAssign (const VectorExpression< E > &e)
 Subtracts the elements of the vector expression e from this vector without intermediate temporary. More...
 
BoundedVectorminusAssign (InitializerListType l)
 Subtracts the contents of the initializer list l element-wise from this vector without intermediate temporary. More...
 
void swap (BoundedVector &v)
 Swaps the contents of this bounded vector with those of v. More...
 
void clear (const ValueType &v=ValueType())
 Sets every element of the vector to the value v (size is unchanged). More...
 
void resize (SizeType n)
 Resizes the vector to n elements (new elements are left value-uninitialized). More...
 
void resize (SizeType n, const ValueType &v)
 Resizes the vector to n elements; newly added elements are set to v. More...
 
- Public Member Functions inherited from CDPL::Math::VectorContainer< BoundedVector< 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 MaxSize = N
 The compile-time maximum capacity N. More...
 

Friends

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

Additional Inherited Members

- Protected Member Functions inherited from CDPL::Math::VectorContainer< BoundedVector< 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::BoundedVector< T, N >

Variable-size vector with a fixed upper capacity N stored in a stack-allocated array.

Template Parameters
TThe scalar value type.
NThe maximum vector size.

Member Typedef Documentation

◆ ValueType

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

The scalar value type.

◆ Reference

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

Mutable reference type to an element.

◆ ConstReference

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

Constant reference type to an element.

◆ SizeType

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

The unsigned size type.

◆ DifferenceType

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

The signed difference type.

◆ ArrayType

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

The fixed-capacity C-array type used for in-memory storage.

◆ Pointer

template<typename T , std::size_t N>
typedef T* CDPL::Math::BoundedVector< 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::BoundedVector< 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::BoundedVector< 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::BoundedVector< 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::BoundedVector< T, N >::VectorTemporaryType

Concrete temporary vector type used by expression-template machinery (one element larger than the bound).

◆ SharedPointer

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

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

◆ InitializerListType

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

The initializer-list type accepted by constructors and assignment.

Constructor & Destructor Documentation

◆ BoundedVector() [1/6]

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

Constructs an empty bounded vector (size zero, capacity N).

◆ BoundedVector() [2/6]

template<typename T , std::size_t N>
CDPL::Math::BoundedVector< T, N >::BoundedVector ( SizeType  n)
inlineexplicit

Constructs a bounded vector of size n with value-initialized elements.

Parameters
nThe initial element count.
Exceptions
Base::SizeErrorif n exceeds the bound N.

◆ BoundedVector() [3/6]

template<typename T , std::size_t N>
CDPL::Math::BoundedVector< T, N >::BoundedVector ( SizeType  n,
const ValueType v 
)
inline

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

Parameters
nThe initial element count.
vThe initial element value.
Exceptions
Base::SizeErrorif n exceeds the bound N.

◆ BoundedVector() [4/6]

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

Constructs a copy of the bounded vector v.

Parameters
vThe bounded vector to copy.

◆ BoundedVector() [5/6]

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

Constructs a bounded vector with the contents of the initializer list l.

Parameters
lThe initializer list providing the initial elements.
Exceptions
Base::SizeErrorif l.size() exceeds the bound N.

◆ BoundedVector() [6/6]

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

Constructs a bounded vector from the vector expression e.

Template Parameters
EThe source vector expression type.
Parameters
eThe source vector expression.
Exceptions
Base::SizeErrorif the size of e exceeds the bound N.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T , std::size_t N>
Reference CDPL::Math::BoundedVector< 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::BoundedVector< 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::BoundedVector< 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::BoundedVector< 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::BoundedVector< T, N >::isEmpty ( ) const
inline

Tells whether the vector is empty.

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

◆ getSize()

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

Returns the current element count.

Returns
The number of elements.

◆ getMaxSize()

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

Returns the compile-time maximum capacity N.

Returns
The maximum element count.

◆ getData() [1/2]

template<typename T , std::size_t N>
Pointer CDPL::Math::BoundedVector< 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::BoundedVector< 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>
BoundedVector& CDPL::Math::BoundedVector< T, N >::operator= ( const BoundedVector< T, N > &  v)
inline

Copy-assigns the elements of v to this bounded vector.

Parameters
vThe source bounded vector.
Returns
A reference to itself.

◆ operator=() [2/4]

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

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

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

◆ operator=() [3/4]

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

Assigns the contents of the vector container c to this bounded 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 >
BoundedVector& CDPL::Math::BoundedVector< T, N >::operator= ( const VectorExpression< E > &  e)
inline

Assigns the vector expression e to this bounded 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 >
BoundedVector& CDPL::Math::BoundedVector< T, N >::operator+= ( const VectorContainer< C > &  c)
inline

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

Adds the contents of the initializer list l element-wise to this bounded 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 >
BoundedVector& CDPL::Math::BoundedVector< T, N >::operator+= ( const VectorExpression< E > &  e)
inline

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

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

Subtracts the contents of the initializer list l element-wise from this bounded 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 >
BoundedVector& CDPL::Math::BoundedVector< T, N >::operator-= ( const VectorExpression< E > &  e)
inline

Subtracts the vector expression e element-wise from this bounded 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, BoundedVector>::type& CDPL::Math::BoundedVector< 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, BoundedVector>::type& CDPL::Math::BoundedVector< 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 >
BoundedVector& CDPL::Math::BoundedVector< T, N >::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.
Exceptions
Base::SizeErrorif the size of e exceeds the bound N.

◆ assign() [2/2]

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

Resizes this vector to match l and copies the elements of l in.

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

◆ plusAssign() [1/2]

template<typename T , std::size_t N>
template<typename E >
BoundedVector& CDPL::Math::BoundedVector< 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>
BoundedVector& CDPL::Math::BoundedVector< 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 >
BoundedVector& CDPL::Math::BoundedVector< 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>
BoundedVector& CDPL::Math::BoundedVector< 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::BoundedVector< T, N >::swap ( BoundedVector< T, N > &  v)
inline

Swaps the contents of this bounded vector with those of v.

Parameters
vThe bounded vector to swap with.

◆ clear()

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

Sets every element of the vector to the value v (size is unchanged).

Parameters
vThe fill value.

◆ resize() [1/2]

template<typename T , std::size_t N>
void CDPL::Math::BoundedVector< T, N >::resize ( SizeType  n)
inline

Resizes the vector to n elements (new elements are left value-uninitialized).

Parameters
nThe new element count.
Exceptions
Base::SizeErrorif n exceeds the bound N.

◆ resize() [2/2]

template<typename T , std::size_t N>
void CDPL::Math::BoundedVector< T, N >::resize ( SizeType  n,
const ValueType v 
)
inline

Resizes the vector to n elements; newly added elements are set to v.

Parameters
nThe new element count.
vThe fill value for newly added elements.
Exceptions
Base::SizeErrorif n exceeds the bound N.

Friends And Related Function Documentation

◆ swap

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

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

Parameters
v1The first bounded vector.
v2The second bounded vector.

Member Data Documentation

◆ MaxSize

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

The compile-time maximum capacity N.


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