|
Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
|
Public Types | |
| using | numerical_scale_type = NumericalScale |
| using | underlying_type = T |
| < Type of the numerical scale of the unit (e.g. linear_scale) | |
| using | value_type = T |
| < Type of the underlying storage of the unit (e.g. double) | |
| using | conversion_factor = ConversionFactor |
| < Synonym for underlying type. May be removed in future versions. Prefer underlying_type. | |
Public Member Functions | |
| constexpr | unit ()=default |
| < Type of conversion_factor the unit represents (e.g. meters) | |
| constexpr | unit (const unit &)=default |
| default copy constructor. | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> requires traits::is_same_dimension_unit_v<unit<ConversionFactorRhs, Ty, NsRhs>, unit> && detail::is_losslessly_convertible_unit <unit<ConversionFactorRhs, Ty, NsRhs>, unit> | |
| constexpr | unit (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) noexcept |
| converting constructor | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> requires (traits::is_same_dimension_unit_v<unit<ConversionFactorRhs, Ty, NsRhs>, unit> && !detail::is_losslessly_convertible_unit <unit<ConversionFactorRhs, Ty, NsRhs>, unit> && std::is_floating_point_v<Ty> && std::is_integral_v<T>) | |
| consteval | unit (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) |
| compile-time narrowing converting constructor | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> requires (traits::is_same_dimension_unit_v<unit<ConversionFactorRhs, Ty, NsRhs>, unit> && !detail::is_losslessly_convertible_unit <unit<ConversionFactorRhs, Ty, NsRhs>, unit> && std::is_integral_v<Ty> && std::is_integral_v<T>) | |
| consteval | unit (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) |
| compile-time exact integral converting constructor | |
| template<ArithmeticType Ty> requires (!traits::is_dimensionless_unit<ConversionFactor>::value && detail::is_losslessly_convertible<Ty, T>) | |
| constexpr | unit (Ty value) noexcept |
| constructor | |
| template<ArithmeticType Ty> requires detail::is_losslessly_convertible<Ty, T> | |
| constexpr | unit (Ty value, linearized_value_t) noexcept |
| constructor | |
| template<ArithmeticType Ty> requires traits::is_dimensionless_unit<ConversionFactor>::value && detail::is_losslessly_convertible<Ty, T> | |
| constexpr | unit (Ty value) noexcept |
| constructor | |
| template<ArithmeticType Rep, RatioType Period> requires detail::is_time_conversion_factor<ConversionFactor> && detail::is_losslessly_convertible<Rep, T> && detail::is_losslessly_convertible_unit<units::unit<units::conversion_factor<Period, dimension::time>, Rep>, unit> | |
| constexpr | unit (const std::chrono::duration< Rep, Period > &value) noexcept |
| chrono constructor | |
| constexpr unit & | operator= (const unit &rhs) noexcept=default |
| default assignment | |
| template<ConversionFactorType Cf = ConversionFactor> requires traits::is_dimensionless_unit<Cf>::value | |
| constexpr unit & | operator= (const underlying_type &rhs) noexcept |
| assignment | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> | |
| constexpr bool | operator< (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| less-than | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> | |
| constexpr bool | operator<= (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| less-than or equal | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> | |
| constexpr bool | operator> (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| greater-than | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> | |
| constexpr bool | operator>= (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| greater-than or equal | |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> requires (std::floating_point<T> || std::floating_point<Ty>) | |
| constexpr bool | operator== (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| equality | |
|
template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> requires (std::integral<T> && std::integral<Ty>) | |
| constexpr bool | operator== (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| template<ConversionFactorType ConversionFactorRhs, ArithmeticType Ty, NumericalScaleType< Ty > NsRhs> | |
| constexpr bool | operator!= (const unit< ConversionFactorRhs, Ty, NsRhs > &rhs) const noexcept |
| inequality | |
| constexpr underlying_type | raw () const noexcept |
| scaled unit value | |
| constexpr auto | value () const noexcept |
| unit value | |
| template<ArithmeticType Ty> | |
| constexpr Ty | to () const noexcept |
| unit value | |
| template<template< class > class UnitType> requires same_dimension<UnitType<T>, unit> | |
| constexpr UnitType< T > | to () const noexcept |
| conversion to a named unit | |
| constexpr T | to_linearized () const noexcept |
| linearized unit value | |
| template<ConversionFactorType Cf, ArithmeticType Ty = T> | |
| constexpr unit< Cf, Ty > | convert () const noexcept |
| conversion | |
| template<template< class > class UnitType> requires same_dimension<UnitType<T>, unit> | |
| constexpr UnitType< T > | convert () const noexcept |
| conversion | |
| template<ArithmeticType Ty> requires traits::is_dimensionless_unit<ConversionFactor>::value | |
| constexpr | operator Ty () const noexcept |
| implicit type unsafe conversion. | |
| template<ArithmeticType Ty> requires (!traits::is_dimensionless_unit<ConversionFactor>::value) | |
| constexpr | operator Ty () const noexcept |
| explicit type unsafe conversion. | |
| template<ArithmeticType Rep, RatioType Period, ConversionFactorType Cf = ConversionFactor> requires detail::is_time_conversion_factor<Cf> && detail::is_losslessly_convertible<T, Rep> | |
| constexpr | operator std::chrono::duration< Rep, Period > () const noexcept |
| chrono implicit type conversion. | |
| template<UnitType Unit = unit> | |
| constexpr const char * | name () const noexcept |
| returns the unit name | |
| template<UnitType Unit = unit> | |
| constexpr const char * | abbreviation () const noexcept |
| returns the unit abbreviation | |
Public Attributes | |
| T | _linearized_value |
| Not to be used as part of the official API, this member is public to allow the use of units as NTTP types. | |
Additional Inherited Members | |
| Static Public Member Functions inherited from units::linear_scale | |
| template<class T> | |
| static constexpr T | linearize (const T value) noexcept |
| linearizes value | |
| template<class T> | |
| static constexpr T | scale (const T value) noexcept |
| scales value | |
|
inlineconstexprnoexcept |
converting constructor
performs implicit unit conversions if required.
| [in] | rhs | unit to copy. |
|
inlineconsteval |
compile-time narrowing converting constructor
Constructs an integral-underlying unit from a same-dimension floating-point one when the conversion is exact — the case the ordinary converting constructor rejects as lossy. It is consteval, so it participates only in a constant-evaluated context (feet<int> f = 16_ft;); a value not exactly representable in the target (a fractional or out-of-range magnitude, e.g. 16.5_ft) makes the constructor a non-constant expression and the program ill-formed. A run-time floating-to-integral unit conversion remains rejected. Wholeness is judged on the stored point count (raw()), so a ratio-dimensionless unit converts correctly too (percent<int> p = 1_pct; is percent<int> holding 1, not a rejected 0.01).
| [in] | rhs | unit to convert. |
|
inlineconsteval |
compile-time exact integral converting constructor
Constructs an integral-underlying unit from a same-dimension integral one of a FINER unit when the value is an exact whole number of this (coarser) unit — the case the ordinary converting constructor rejects as potentially-lossy because a run-time value need not divide evenly (bytes<int> b = 16_bit; is 2, but a run-time bits<int> might be 17). It is consteval, so it participates only in a constant-evaluated context; a value that is not a whole number of the target unit (17_bit into bytes<int>) makes the constructor a non-constant expression and the program ill-formed — never a silent truncation. The exactness test is exact integer arithmetic in a double-width intermediate, so it cannot be defeated by an intermediate overflow. A run-time integral-to-coarser-integral unit conversion remains rejected; use round/floor/ ceil/trunc<To> for a deliberate run-time rounding.
| [in] | rhs | unit to convert. |
|
inlineexplicitconstexprnoexcept |
|
inlineexplicitconstexprnoexcept |
|
inlineconstexprnoexcept |
constructor
enable implicit conversions from T types ONLY for linear dimensionless units
| [in] | value | value of the unit |
|
inlineconstexprnoexcept |
chrono constructor
enable implicit conversions from std::chrono::duration types ONLY for time units
| [in] | value | value of the unit |
|
inlineconstexprnoexcept |
conversion
Converts to a different unit. Units can be converted to other units implicitly, but this can be used in cases where the explicit notation of a conversion is beneficial, or where a prvalue unit is needed.
| UnitType | unit type to convert to |
|
inlineconstexprnoexcept |
conversion
Converts to a different unit. Units can be converted to other units implicitly, but this can be used in cases where the explicit notation of a conversion is beneficial, or where an prvalue unit is needed.
| Cf | conversion factor of the unit to convert to |
| Ty | underlying type of the unit to convert to |
|
inlineconstexprnoexcept |
chrono implicit type conversion.
only enabled for time unit types.
|
inlineexplicitconstexprnoexcept |
explicit type unsafe conversion.
only enabled for non-dimensionless unit types.
|
inlineconstexprnoexcept |
implicit type unsafe conversion.
only enabled for dimensionless unit types.
|
inlineconstexprnoexcept |
inequality
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
less-than
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
less-than or equal
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
assignment
performs implicit conversions from built-in types ONLY for dimensionless units
| [in] | rhs | value to copy. |
|
constexprdefaultnoexcept |
default assignment
performs implicit unit conversions if required.
| [in] | rhs | unit to copy. |
|
inlineconstexprnoexcept |
equality
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
greater-than
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
greater-than or equal
compares the linearized value of two units. Performs unit conversions if necessary.
| [in] | rhs | right-hand side unit for the comparison |
|
inlineconstexprnoexcept |
scaled unit value
does NOT normalize dimensionless values.
|
inlineconstexprnoexcept |
conversion to a named unit
Converts to a different named unit of the same dimension, e.g. (100.0_cm).to<meters>(). The named-template spelling of convert(); provided so a single accessor reads for both underlying-type extraction (to<double>()) and dimensioned conversion (to<meters>()).
| UnitType | unit class template to convert to |
|
inlineconstexprnoexcept |
unit value
|
inlineconstexprnoexcept |
linearized unit value
|
inlineconstexprnoexcept |
unit value
Normalizes dimensionless values to remove any scale factor they may have. E.g. percent(50).value() == 0.5.