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

Constant vector expression \( e_i \) that contains 1 at a single specified index and 0 elsewhere. More...

#include <Vector.hpp>

+ Inheritance diagram for CDPL::Math::UnitVector< T >:

Public Types

typedef T ValueType
 The scalar value type. More...
 
typedef const T & Reference
 Reference type (always a const reference — elements are immutable). 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 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 Vector< T > VectorTemporaryType
 Concrete temporary vector type used by expression-template machinery. More...
 
- Public Types inherited from CDPL::Math::VectorContainer< UnitVector< T > >
typedef UnitVector< 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

 UnitVector ()
 Constructs an empty unit vector (size zero, index zero). More...
 
 UnitVector (SizeType n, SizeType i)
 Constructs a unit vector of size n with the 1 entry at index i. More...
 
 UnitVector (const UnitVector &v)
 Constructs a copy of the unit vector v. More...
 
ConstReference operator[] (SizeType i) const
 Returns a const 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. More...
 
bool isEmpty () const
 Tells whether the vector has zero logical size. More...
 
SizeType getSize () const
 Returns the logical element count. More...
 
SizeType getIndex () const
 Returns the index of the non-zero (unit) entry. More...
 
SizeType getMaxSize () const
 Returns the maximum representable element count. More...
 
UnitVectoroperator= (const UnitVector &v)
 Copy-assigns the size and unit index from v. More...
 
void resize (SizeType n)
 Resizes the logical element count to n. More...
 
void swap (UnitVector &v)
 Swaps the size and unit index with v. More...
 
- Public Member Functions inherited from CDPL::Math::VectorContainer< UnitVector< 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 (UnitVector &v1, UnitVector &v2)
 ADL-enabled free-function form of swap(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from CDPL::Math::VectorContainer< UnitVector< 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>
class CDPL::Math::UnitVector< T >

Constant vector expression \( e_i \) that contains 1 at a single specified index and 0 elsewhere.

Template Parameters
TThe scalar value type.

Member Typedef Documentation

◆ ValueType

template<typename T >
typedef T CDPL::Math::UnitVector< T >::ValueType

The scalar value type.

◆ Reference

template<typename T >
typedef const T& CDPL::Math::UnitVector< T >::Reference

Reference type (always a const reference — elements are immutable).

◆ ConstReference

template<typename T >
typedef const T& CDPL::Math::UnitVector< T >::ConstReference

Constant reference type to an element.

◆ SizeType

template<typename T >
typedef std::size_t CDPL::Math::UnitVector< T >::SizeType

The unsigned size type.

◆ DifferenceType

template<typename T >
typedef std::ptrdiff_t CDPL::Math::UnitVector< T >::DifferenceType

The signed difference type.

◆ ClosureType

template<typename T >
typedef VectorReference<SelfType> CDPL::Math::UnitVector< T >::ClosureType

Closure type used when this vector appears inside another expression.

◆ ConstClosureType

template<typename T >
typedef const VectorReference<const SelfType> CDPL::Math::UnitVector< T >::ConstClosureType

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

◆ VectorTemporaryType

template<typename T >
typedef Vector<T> CDPL::Math::UnitVector< T >::VectorTemporaryType

Concrete temporary vector type used by expression-template machinery.

Constructor & Destructor Documentation

◆ UnitVector() [1/3]

template<typename T >
CDPL::Math::UnitVector< T >::UnitVector ( )
inline

Constructs an empty unit vector (size zero, index zero).

◆ UnitVector() [2/3]

template<typename T >
CDPL::Math::UnitVector< T >::UnitVector ( SizeType  n,
SizeType  i 
)
inline

Constructs a unit vector of size n with the 1 entry at index i.

Parameters
nThe element count.
iThe zero-based index of the non-zero entry.

◆ UnitVector() [3/3]

template<typename T >
CDPL::Math::UnitVector< T >::UnitVector ( const UnitVector< T > &  v)
inline

Constructs a copy of the unit vector v.

Parameters
vThe unit vector to copy.

Member Function Documentation

◆ operator[]()

template<typename T >
ConstReference CDPL::Math::UnitVector< T >::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 either 1 (if i equals the unit index) or 0.
Exceptions
Base::IndexErrorif i is out of range.

◆ operator()()

template<typename T >
ConstReference CDPL::Math::UnitVector< T >::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 either 1 (if i equals the unit index) or 0.
Exceptions
Base::IndexErrorif i is out of range.

◆ isEmpty()

template<typename T >
bool CDPL::Math::UnitVector< T >::isEmpty ( ) const
inline

Tells whether the vector has zero logical size.

Returns
true if the logical size is zero, and false otherwise.

◆ getSize()

template<typename T >
SizeType CDPL::Math::UnitVector< T >::getSize ( ) const
inline

Returns the logical element count.

Returns
The element count.

◆ getIndex()

template<typename T >
SizeType CDPL::Math::UnitVector< T >::getIndex ( ) const
inline

Returns the index of the non-zero (unit) entry.

Returns
The zero-based unit index.

◆ getMaxSize()

template<typename T >
SizeType CDPL::Math::UnitVector< T >::getMaxSize ( ) const
inline

Returns the maximum representable element count.

Returns
The maximum element count.

◆ operator=()

template<typename T >
UnitVector& CDPL::Math::UnitVector< T >::operator= ( const UnitVector< T > &  v)
inline

Copy-assigns the size and unit index from v.

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

◆ resize()

template<typename T >
void CDPL::Math::UnitVector< T >::resize ( SizeType  n)
inline

Resizes the logical element count to n.

Parameters
nThe new element count.

◆ swap()

template<typename T >
void CDPL::Math::UnitVector< T >::swap ( UnitVector< T > &  v)
inline

Swaps the size and unit index with v.

Parameters
vThe unit vector to swap with.

Friends And Related Function Documentation

◆ swap

template<typename T >
void swap ( UnitVector< T > &  v1,
UnitVector< T > &  v2 
)
friend

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

Parameters
v1The first unit vector.
v2The second unit vector.

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