BoB robotics
The Brains on Board robotics library
Explicit Conversion

Functions used to convert values of one logical type to another. More...

Functions

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. More...
 

Detailed Description

Functions used to convert values of one logical type to another.

Function Documentation

◆ unit_cast()

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)
inlineconstexprnoexcept

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
TType to cast the unit type to. Must be a built-in arithmetic type.
Parameters
valueUnit value to cast.
See also
unit_t::to