C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_3_5::section_3_1::quantity< T, Dimension > Class Template Reference

A numerical quanitity with intrinsic dimensions. More...

#include <exercise-3-5.hpp>

Public Member Functions

 quantity (T const x)
 Construct this quantity with an initial value.
 
template<typename OtherDimension >
 quantity (quantity< T, OtherDimension > const &rhs)
 Construct a quantity from another quantity with (possibly) different dimensions.
 
value () const
 Return the current quantity's value.
 

Private Attributes

m_value
 The current value of this quantity.
 

Detailed Description

template<typename T, typename Dimension>
class exercise_3_5::section_3_1::quantity< T, Dimension >

A numerical quanitity with intrinsic dimensions.

To prevent accidental arithmetic between quantities that make no sense, we inlclude the units/dimensions for context. Thus, you cannot add 5 meters to 10 degrees and get a result.

Template Parameters
TThe storage container for the numerical value.
DimensionsOne of the dimension types (e.g., mass, length, force).

Definition at line 71 of file exercise-3-5.hpp.

Constructor & Destructor Documentation

◆ quantity() [1/2]

template<typename T , typename Dimension >
exercise_3_5::section_3_1::quantity< T, Dimension >::quantity ( T const  x)
inlineexplicit

Construct this quantity with an initial value.

Parameters
[in]xThe initial value for this quantity.

Definition at line 78 of file exercise-3-5.hpp.

◆ quantity() [2/2]

template<typename T , typename Dimension >
template<typename OtherDimension >
exercise_3_5::section_3_1::quantity< T, Dimension >::quantity ( quantity< T, OtherDimension > const &  rhs)
inline

Construct a quantity from another quantity with (possibly) different dimensions.

Check at compile time for equal dimensions, or we will lose the whole point of creating this class template.

Template Parameters
OtherDimensionsDimensions that must be identical to, or convertable to the current quantity's dimensions.
Parameters
[in]rhsThe quantity to copy.

Definition at line 94 of file exercise-3-5.hpp.

Member Function Documentation

◆ value()

template<typename T , typename Dimension >
T exercise_3_5::section_3_1::quantity< T, Dimension >::value ( ) const
inline

Return the current quantity's value.

Definition at line 102 of file exercise-3-5.hpp.

Member Data Documentation

◆ m_value

template<typename T , typename Dimension >
T exercise_3_5::section_3_1::quantity< T, Dimension >::m_value
private

The current value of this quantity.

Definition at line 106 of file exercise-3-5.hpp.


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