Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
units::conversion_factor< Conversion, BaseUnit, PiExponent, Translation > Struct Template Reference

Type representing an arbitrary conversion factor between units. More...

#include <core.h>

Inheritance diagram for units::conversion_factor< Conversion, BaseUnit, PiExponent, Translation >:
[legend]
Collaboration diagram for units::conversion_factor< Conversion, BaseUnit, PiExponent, Translation >:
[legend]

Public Types

using dimension_type = traits::dimension_of_t<BaseUnit>
using conversion_ratio = std::ratio_multiply<typename BaseUnit::conversion_ratio, Conversion>
using pi_exponent_ratio = std::ratio_add<typename BaseUnit::pi_exponent_ratio, PiExponent>
using translation_ratio = std::ratio_add<std::ratio_multiply<typename BaseUnit::conversion_ratio, Translation>, typename BaseUnit::translation_ratio>

Detailed Description

template<RatioType Conversion, class BaseUnit, RatioType PiExponent = std::ratio<0>, RatioType Translation = std::ratio<0>>
struct units::conversion_factor< Conversion, BaseUnit, PiExponent, Translation >

Type representing an arbitrary conversion factor between units.

conversion_factors are used as tags for the convert function. Each unit is defined by:

  • A std::ratio defining the conversion factor to the dimension type. (e.g. std::ratio<1,12> for inches to feet)
  • A dimension that the unit is derived from (or a unit dimension. Must be of type conversion_factor or dimension_t)
  • An exponent representing factors of PI required by the conversion. (e.g. std::ratio<-1> for a radians to degrees conversion)
  • a ratio representing a datum translation required for the conversion (e.g. std::ratio<32> for a Fahrenheit to Celsius conversion)

Typically, a specific conversion factor, like meters, would be implemented as a strong type alias of conversion_factor, i.e. struct meters : conversion_factor<std::ratio<1>, units::dimension::length> {};, or type alias, i.e. using inches = conversion_factor<std::ratio<1,12>, feet>.

Template Parameters
Conversionstd::ratio representing dimensionless multiplication factor.
BaseUnitUnit type which this unit is derived from. May be a dimension_t, or another conversion_factor.
PiExponentstd::ratio representing the exponent of pi required by the conversion.
Translationstd::ratio representing any datum translation required by the conversion.

The documentation for this struct was generated from the following file:
  • /home/runner/work/units/units/include/units/core.h