Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
Unit Types

Defines a series of classes which contain dimensioned values. More...

Macros

#define MSVC_EBO
 Describes objects that represent quantities of a given unit.

Functions

template<UnitType UnitType, ArithmeticType T>
requires detail::is_losslessly_convertible<T, typename UnitType::underlying_type>
constexpr UnitType units::make_unit (const T value) noexcept
 Constructs a unit container from an arithmetic type.

Detailed Description

Defines a series of classes which contain dimensioned values.

Unit types store a value, and support various arithmetic operations.

Macro Definition Documentation

◆ MSVC_EBO

#define MSVC_EBO

Describes objects that represent quantities of a given unit.

Stores a value which represents a quantity in the given units. Units (except dimensionless units) are not convertible to arithmetic types, in order to provide type safety in dimensional analysis. Units are implicitly convertible to other units types of the same dimension, if such conversion is lossless. Units support various types of arithmetic operations, depending on their scale type.

The value of an unit can only be set on construction, or changed by assignment from another unit type. If necessary, the underlying value can be accessed using raw():

meter_t m(5.0);
double val = m.raw(); // val == 5.0

.

Template Parameters
ConversionFactorconversion_factor of the represented unit (e.g. meters)
Tunderlying type of the storage. Defaults to UNIT_LIB_DEFAULT_TYPE.
NumericalScaleoptional scale class for the units. Defaults to linear (i.e. does not scale the unit value). Examples of non-linear scales could be logarithmic, decibel, or richter scales. Numerical scales must adhere to the numerical-scale concept, i.e. is_numerical_scale_v<...> must be true.
See also

Function Documentation

◆ make_unit()

template<UnitType UnitType, ArithmeticType T>
requires detail::is_losslessly_convertible<T, typename UnitType::underlying_type>
UnitType units::make_unit ( const T value)
constexprnoexcept

Constructs a unit container from an arithmetic type.

make_unit can be used to construct a unit container from an arithmetic type, as an alternative to using the explicit constructor. Unlike the explicit constructor it forces the user to explicitly specify the units.

Template Parameters
UnitTypeType to construct.
TArithmetic type.
Parameters
[in]valueArithmetic value that represents a quantity in units of UnitType.