Conversion(3)
| Conversion(3) | Unit Conversion and Dimensional Analysis Library | Conversion(3) |
NAME
Conversion - Explicit Conversion
- Functions used to convert values of one logical type to another.
SYNOPSIS
Functions
template<class UnitFrom , class UnitTo , typename T =
double> static constexpr T units::convert (const T &value)
noexcept
converts a value from one type to another. template<typename T ,
typename Units , class =
std::enable_if_t<std::is_arithmetic<T>::value &&
traits::is_unit_t<Units>::value>> constexpr T
units::unit_cast (const Units &value) noexcept
Casts a unit container to an arithmetic type.
Detailed Description
Functions used to convert values of one logical type to another.
Function Documentation
template<class UnitFrom , class UnitTo , typename T = double> static constexpr T units::convert (const T & value) [inline], [static], [constexpr], [noexcept]
converts a value from one type to another. Converts a value of a built-in arithmetic type to another unit. This does not change the type of value, only what it contains. E.g.
double result = convert<length::meters, length::feet>(1.0); // result == 3.28084
See also
Template Parameters
UnitTo unit tag to convert value to. Must be a unit type (i.e. is_unit<UnitTo>::value == true), and must be convertible from UnitFrom (i.e. is_convertible_unit<UnitFrom, UnitTo>::value == true).
T type of value. It is inferred from value, and is expected to be a built-in arithmetic type.
Parameters
Returns
template<typename T , typename Units , class = std::enable_if_t<std::is_arithmetic<T>::value && traits::is_unit_t<Units>::value>> constexpr T units::unit_cast (const Units & value) [inline], [constexpr], [noexcept]
Casts a unit container to an arithmetic type. unit_cast can be used to remove the strong typing from a unit class, and convert it to a built-in arithmetic type. This may be useful for compatibility with libraries and legacy code that don't support unit_t types. E.g
meter_t unitVal(5); double value = units::unit_cast<double>(unitVal); // value = 5.0
Template Parameters
Parameters
See also
Author
Generated automatically by Doxygen for Unit Conversion and Dimensional Analysis Library from the source code.
| Wed Mar 29 2023 | Version 2.3.0 |
