|
| Quantity (T x=0) |
| Default constructor. More...
|
|
| Quantity (const Quantity< T, U, Ratio > &other) |
| Copy constructor. More...
|
|
template<typename OtherRatio > |
| Quantity (const Quantity< T, U, OtherRatio > &other) |
| Copy constructor from same quantity type with different ratio. More...
|
|
T | value () const |
| Get underlying value of the quantity, value represented with current unit and ratio will be returned. More...
|
|
void | set_value (T value) |
| Set underlying value of the quantity. More...
|
|
T | standard_value () const |
| Get standard value of the quantity, Ratio is reverted to std::ratio<1> . More...
|
|
void | set_standard_value (T value) |
| Get standard value of the quantity, Ratio is reverted to std::ratio<1> . More...
|
|
template<typename OtherRatio > |
Quantity< T, U, Ratio > & | operator+= (const Quantity< T, U, OtherRatio > &other) |
| Add & assignment operator overload, add value from same type with maybe different ratio, operand value will be converted by ratio_type before performing add. More...
|
|
Quantity< T, U, Ratio > & | operator= (const Quantity< T, U, Ratio > &other) |
| Assisgnment operator overload. More...
|
|
template<typename OtherRatio > |
Quantity< T, U, Ratio > & | operator= (const Quantity< T, U, OtherRatio > &other) |
| Assisgnment operator overload, assign value from same type but different ratio, operand value will be converted by ratio_type before performing assignment. More...
|
|
template<typename OtherRatio > |
bool | operator== (const Quantity< T, U, OtherRatio > &other) const |
| Equality operator overload, value will be convered to same ratio before comparison. More...
|
|
template<typename OtherRatio > |
bool | operator!= (const Quantity< T, U, OtherRatio > &other) const |
| Inequality operator overload, value will be convered to same ratio before comparison. More...
|
|
template<typename OtherRatio > |
bool | operator< (const Quantity< T, U, OtherRatio > &other) const |
| Less than operator overload, value will be convered to same ratio before comparison. More...
|
|
template<typename OtherRatio > |
bool | operator<= (const Quantity< T, U, OtherRatio > &other) const |
| Less or equal operator overload, value will be convered to same ratio before comparison. More...
|
|
template<typename OtherRatio > |
bool | operator> (const Quantity< T, U, OtherRatio > &other) const |
| Larger than operator overload, value will be convered to same ratio before comparison. More...
|
|
template<typename OtherRatio > |
bool | operator>= (const Quantity< T, U, OtherRatio > &other) const |
| Larger or equal operator overload, value will be convered to same ratio before comparison. More...
|
|
|
(Note that these are not member functions.)
|
template<typename T , typename U , typename Ratio1 , typename Ratio2 > |
Quantity< T, U, Ratio1 > | operator+ (Quantity< T, U, Ratio1 > lhs, Quantity< T, U, Ratio2 > rhs) |
| Plus operator overload, values will be converted to same ratio before calculation, both inputs should have same value type and unit type. More...
|
|
template<typename T , typename U , typename Ratio1 , typename Ratio2 > |
Quantity< T, U, Ratio1 > | operator- (Quantity< T, U, Ratio1 > &lhs, Quantity< T, U, Ratio2 > rhs) |
| Subtract operator overload, values will be converted to same ratio before calculation, both inputs should have same value type and unit type. More...
|
|
template<typename T , typename Unit1 , typename Ratio1 , typename Unit2 , typename Ratio2 > |
Quantity< T, UnitMultiply< Unit1, Unit2 >, Ratio1 > | operator* (Quantity< T, Unit1, Ratio1 > lhs, Quantity< T, Unit2, Ratio2 > rhs) |
| Multiply operator overload, values will be converted to same ratio before calculation, inputs can have different unit type, a new unit type will be generated. More...
|
|
template<typename T , typename Unit1 , typename Ratio1 , typename Unit2 , typename Ratio2 > |
Quantity< T, UnitDivide< Unit1, Unit2 >, Ratio1 > | operator/ (Quantity< T, Unit1, Ratio1 > lhs, Quantity< T, Unit2, Ratio2 > rhs) |
| Divide operator overload, values will be converted to same ratio before calculation, inputs can have different unit type, a new unit type will be generated. More...
|
|
template<int factor, typename T , typename U , typename Ratio > |
Quantity< T, UnitPow< U, factor >, std::ratio< 1 > > | pow (const Quantity< T, U, Ratio > &x) |
| Power calculation, performed both on value and unit, ratio will be casted to std::ratio<1> . More...
|
|
template<int factor, typename T , typename U , typename Ratio > |
Quantity< T, UnitRoot< U, factor >, std::ratio< 1 > > | root (const Quantity< T, U, Ratio > &x) |
| Root calculation, performed both on value and unit, ratio will be casted to std::ratio<1> . More...
|
|
template<typename NewRatio , typename T , typename U , typename Ratio > |
Quantity< T, U, NewRatio > | quantity_cast (Quantity< T, U, Ratio > x) |
| Cast a quantity to another ratio, value will be converted too. Sample code for convert to standard value: b = quantity_cast<std::ratio<1>>(a); More...
|
|
|
Common ratios for calculation.
|
typedef std::ratio< 80813362, 25723692 > | ratio_PI |
| Ratio to display π in approximate fraction, with high presion up to . More...
|
|
typedef std::ratio_divide< ratio_PI, std::ratio< 180 > > | ratio_degree |
| Ratio to convert degree into radian, using equation . More...
|
|
|
Ratios for Chinese units of mass and length.
|
typedef std::ratio< 500, 1 > | ratio_length_li |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_length_li, std::ratio< 15 > > | ratio_yin |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_yin, std::ratio< 10 > > | ratio_zhang |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_zhang, std::ratio< 2 > > | ratio_xun |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_zhang, std::ratio< 10 > > | ratio_chi |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_chi, std::ratio< 10 > > | ratio_cun |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_cun, std::ratio< 10 > > | ratio_length_fen |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_length_fen, std::ratio< 10 > > | ratio_length_li2 |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_length_li2, std::ratio< 10 > > | ratio_length_hao |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_length_hao, std::ratio< 10 > > | ratio_length_si |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_length_si, std::ratio< 10 > > | ratio_length_hu |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio< 200000, 3 > | ratio_qing |
| Ratio to convert to suqaremeter. . More...
|
|
typedef std::ratio< 2000, 3 > | ratio_mu |
| Ratio to convert to suqaremeter. . More...
|
|
typedef std::ratio_divide< ratio_mu, std::ratio< 240 > > | ratio_gong |
| Ratio to convert to suqaremeter. . More...
|
|
typedef std::ratio< 50 > | ratio_dan |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio< 1, 2 > | ratio_jin |
| Ratio to convert to kilogram, also called market carry . . More...
|
|
typedef std::ratio_divide< ratio_jin, std::ratio< 10 > > | ratio_liang |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_liang, std::ratio< 10 > > | ratio_qian |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_qian, std::ratio< 10 > > | ratio_mass_fen |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_mass_fen, std::ratio< 10 > > | ratio_mass_li |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_mass_li, std::ratio< 10 > > | ratio_mass_hao |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_mass_hao, std::ratio< 10 > > | ratio_mass_si |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_mass_si, std::ratio< 10 > > | ratio_mass_hu |
| Ratio to convert to kilogram. . More...
|
|
|
Ratios for International Avoirdupois System of yard and pound units.
|
typedef std::ratio_multiply< std::ratio< 1609344ll, 1000000ll >, std::kilo > | ratio_mile |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_mile, std::ratio< 8 > > | ratio_furlong |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_furlong, std::ratio< 10 > > | ratio_chain |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_chain, std::ratio< 22 > > | ratio_yard |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_yard, std::ratio< 16 > > | ratio_nail |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_yard, std::ratio< 3 > > | ratio_feet |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_feet, std::ratio< 12 > > | ratio_inch |
| Ratio to convert to meter. . More...
|
|
typedef std::ratio_divide< ratio_inch, std::ratio< 6 > > | ratio_pica |
| Ratio to convert to meter, with symbol pc . . More...
|
|
typedef std::ratio_divide< ratio_pica, std::ratio< 12 > > | ratio_point |
| Ratio to convert to meter, with symbol 'pt'. . More...
|
|
typedef std::ratio< 10160469088, 10000000 > | ratio_longton |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio< 90718474, 100000 > | ratio_shortton |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio< 5080234544, 100000000 > | ratio_long_hundredweight |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio< 45359237, 1000000 > | ratio_short_hundredweight |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio< 45359237, 100000000 > | ratio_pound |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_pound, std::ratio< 16 > > | ratio_ounce |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_divide< ratio_ounce, std::ratio< 16 > > | ratio_drachm |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_multiply< std::ratio< 6479891, 100000ll >, std::micro > | ratio_grain |
| Ratio to convert to kilogram. . More...
|
|
|
Imperial units of mass and volume
|
typedef ratio_long_hundredweight | ratio_en_hundredweight |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_multiply< ratio_pound, std::ratio< 28 > > | ratio_en_quarter |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_multiply< ratio_pound, std::ratio< 14 > > | ratio_en_stone |
| Ratio to convert to kilogram. . More...
|
|
typedef std::ratio_multiply< std::ratio< 35516328125ll, 10000000000ll >, std::micro > | ratio_en_fluid_dram |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_fluid_dram, std::ratio< 8 > > | ratio_en_fluid_ounce |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_fluid_ounce, std::ratio< 5 > > | ratio_en_gill |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_gill, std::ratio< 2 > > | ratio_en_cup |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_cup, std::ratio< 2 > > | ratio_en_pint |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_pint, std::ratio< 2 > > | ratio_en_quart |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_quart, std::ratio< 4 > > | ratio_en_gallon |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_gallon, std::ratio< 2 > > | ratio_en_peck |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_en_peck, std::ratio< 4 > > | ratio_en_bushel |
| Ratio to convert to cubicmeter. . More...
|
|
|
US units of mass and volume
|
typedef ratio_short_hundredweight | ratio_us_hundredweight |
| Ratio to convert to kilogram . More...
|
|
typedef std::ratio_multiply< std::ratio< 36966911953125ll, 10000000000000ll >, std::micro > | ratio_us_fluid_dram |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_fluid_dram, std::ratio< 8 > > | ratio_us_fluid_ounce |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_divide< ratio_us_fluid_ounce, std::ratio< 6 > > | ratio_us_teaspoons |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_divide< ratio_us_fluid_ounce, std::ratio< 2 > > | ratio_us_tablespoons |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_fluid_ounce, std::ratio< 4 > > | ratio_us_gill |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_gill, std::ratio< 2 > > | ratio_us_cup |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_cup, std::ratio< 2 > > | ratio_us_pint |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_pint, std::ratio< 2 > > | ratio_us_quart |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_quart, std::ratio< 4 > > | ratio_us_gallon |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< std::ratio< 5506104713575ll, 10000000000000ll >, std::milli > | ratio_us_dry_pint |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_dry_pint, std::ratio< 2 > > | ratio_us_dry_quart |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_dry_quart, std::ratio< 4 > > | ratio_us_dry_gallon |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_dry_gallon, std::ratio< 2 > > | ratio_us_dry_peck |
| Ratio to convert to cubicmeter. . More...
|
|
typedef std::ratio_multiply< ratio_us_dry_peck, std::ratio< 4 > > | ratio_us_bushel |
| Ratio to convert to cubicmeter. . More...
|
|
template<typename T, typename U, typename Ratio = std::ratio<1>>
class Dimensional::Quantity< T, U, Ratio >
The Quantity struct is used to describe arithmetic values with units.
- Template Parameters
-
T | Arithmetic type for value. |
U | Unit type for this physical quantity. |
Ratio | Conversion ratio for nonstandard units such as feet or yard. |
This template guarantee strong-typed safe calculation of physical values.
Variables with different unit cannot add, subtract and compare with each other. Multiply, divide, power, root calculation will generate value with unit.
Value is allowd to be described with different Ratio. Calculation with different ratios is safe, and result has same Ratio of first operand.
- See also
- Dimensional Analysis, Unit