C++ Template Metaprogramming
Solutions to the exercises throughout the book
|
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. | |
T | value () const |
Return the current quantity's value. | |
Private Attributes | |
T | m_value |
The current value of this quantity. | |
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.
T | The storage container for the numerical value. |
Dimensions | One of the dimension types (e.g., mass, length, force). |
Definition at line 71 of file exercise-3-5.hpp.
|
inlineexplicit |
Construct this quantity with an initial value.
[in] | x | The initial value for this quantity. |
Definition at line 78 of file exercise-3-5.hpp.
|
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.
OtherDimensions | Dimensions that must be identical to, or convertable to the current quantity's dimensions. |
[in] | rhs | The quantity to copy. |
Definition at line 94 of file exercise-3-5.hpp.
|
inline |
Return the current quantity's value.
Definition at line 102 of file exercise-3-5.hpp.
|
private |
The current value of this quantity.
Definition at line 106 of file exercise-3-5.hpp.