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

namespace representing type traits which can access the properties of types provided by the units library. More...

Classes

struct  has_decibel_scale
 Trait which tests whether a type is inherited from a decibel scale. More...
struct  has_linear_scale
 Trait which tests whether a type is inherited from a linear scale. More...
struct  is_absolute
 Trait which tests whether T is an absolute<U> point wrapper. More...
struct  is_delta
 Trait which tests whether T is a delta<U> amount wrapper. More...
struct  is_dimensionless_unit
struct  is_kind
 Trait which tests whether T is a string-tagged kind<Tag, U>. More...
struct  is_ratio_dimensionless_cf
struct  is_ratio_dimensionless_cf< ConversionFactor, std::void_t< typename ConversionFactor::dimension_type, typename ConversionFactor::conversion_ratio > >
struct  is_same_dimension_conversion_factor
 BinaryTypeTrait for querying whether Cf1 and Cf2 are conversion factors to the same dimension. More...
struct  is_same_dimension_unit
 BinaryTypeTrait for querying whether U1 and U2 are units of the same dimension. More...
struct  is_unit
 Traits which tests if a class is a unit. More...
struct  replace_underlying
 SFINAE-able trait which replaces the underlying type of Unit with Underlying. More...
struct  replace_underlying< Unit, Underlying >
struct  replace_underlying< unit< Cf, T, Ns >, Underlying >
struct  strong
 SFINAE-able trait that maps a conversion_factor to its strengthened type. More...

Typedefs

template<class T>
using is_ratio = detail::is_ratio_impl<T>
 UnaryTypeTrait for querying whether T represents a specialization of std::ratio.
template<class T>
using is_conversion_factor = typename std::is_base_of<units::detail::_conversion_factor, T>::type
template<class T, class Ret>
using is_numerical_scale = std::is_invocable_r<Ret, detail::invocable_scale<T>, Ret>
 Trait which tests whether T meets the requirements for a numerical scale.
template<class T>
using strong_t = typename strong<T>::type
template<class U>
using dimension_of_t = typename units::detail::dimension_of_impl<U>::type
 Names the dimension_t of a conversion_factor.
template<class Unit, class Underlying>
using replace_underlying_t = typename replace_underlying<Unit, Underlying>::type

Variables

template<class T>
constexpr bool is_ratio_v = is_ratio<T>::value
template<class T>
constexpr bool is_conversion_factor_v = is_conversion_factor<T>::value
template<class T>
constexpr bool is_unit_v = is_unit<T>::value && !std::is_arithmetic_v<T>
template<class T, class Ret>
constexpr bool is_numerical_scale_v = is_numerical_scale<T, Ret>::value
template<class ConversionFactor>
constexpr bool is_ratio_dimensionless_cf_v = is_ratio_dimensionless_cf<ConversionFactor>::value
template<ConversionFactorType Cf1, ConversionFactorType Cf2>
constexpr bool is_same_dimension_conversion_factor_v = is_same_dimension_conversion_factor<Cf1, Cf2>::value
template<ConversionFactorType Cf>
constexpr bool is_affine_conversion_factor_v = !std::ratio_equal_v<typename conversion_factor_traits<Cf>::translation_ratio, std::ratio<0>>
 true when a conversion factor carries a non-zero datum offset — i.e.
template<UnitType U>
constexpr bool is_affine_unit_v = is_affine_conversion_factor_v<typename unit_traits<U>::conversion_factor>
 true when a unit type is affine — its conversion factor carries a non-zero datum offset (e.g.
template<UnitType U1, UnitType U2>
constexpr bool is_same_dimension_unit_v = is_same_dimension_unit<U1, U2>::value
template<typename... T>
constexpr bool has_linear_scale_v = has_linear_scale<T...>::value
template<typename... T>
constexpr bool has_decibel_scale_v = has_decibel_scale<T...>::value
template<typename T>
constexpr bool is_dimensionless_unit_v = is_dimensionless_unit<T>::value
template<class T>
constexpr bool is_absolute_v = is_absolute<T>::value
template<class T>
constexpr bool is_delta_v = is_delta<T>::value
template<class T>
constexpr bool is_kind_v = is_kind<T>::value

Detailed Description

namespace representing type traits which can access the properties of types provided by the units library.

UnaryTypeTrait for querying whether T represents a unit of dimensionless

< Represents the type of class Cf with the binary 'exbi' prefix appended.

E.g. exbi<bytes> represents bytes*2^60

Template Parameters
Cfunit type to apply the prefix to.

The base characteristic is a specialization of the template std::bool_constant. Use is_dimensionless_unit_v<T> to test the unit represents a dimensionless quantity.

Template Parameters
Ttype to test

Typedef Documentation

◆ dimension_of_t

template<class U>
using units::traits::dimension_of_t = typename units::detail::dimension_of_impl<U>::type

Names the dimension_t of a conversion_factor.

Since conversion_factors nest, their dimension_type typedef will not always be a dimension_t (or unit dimension).

◆ is_conversion_factor

template<class T>
using units::traits::is_conversion_factor = typename std::is_base_of<units::detail::_conversion_factor, T>::type
       @ingroup     TypeTraits
       @brief       `UnaryTypeTrait` for querying whether `T` represents a conversion factor.
       @details     The base characteristic is a specialization of the template `std::bool_constant`.
  • * Use is_conversion_factor_v<T> to test whether T represents a conversion factor.

◆ is_ratio

template<class T>
using units::traits::is_ratio = detail::is_ratio_impl<T>

UnaryTypeTrait for querying whether T represents a specialization of std::ratio.

The base characteristic is a specialization of the template std::bool_constant. Use is_ratio_v<T> to test whether T is a specialization of std::ratio.

Variable Documentation

◆ is_affine_conversion_factor_v

template<ConversionFactorType Cf>
bool units::traits::is_affine_conversion_factor_v = !std::ratio_equal_v<typename conversion_factor_traits<Cf>::translation_ratio, std::ratio<0>>
inlineconstexpr

true when a conversion factor carries a non-zero datum offset — i.e.

it is AFFINE, not a pure scale (the archetype is temperature: degrees Celsius/Fahrenheit have an offset to the Kelvin datum). Absolute affine quantities do not add meaningfully, and their difference is a pure delta (the offsets cancel).

Template Parameters
Cfthe conversion factor to test.

◆ is_affine_unit_v

template<UnitType U>
bool units::traits::is_affine_unit_v = is_affine_conversion_factor_v<typename unit_traits<U>::conversion_factor>
inlineconstexpr

true when a unit type is affine — its conversion factor carries a non-zero datum offset (e.g.

a temperature in degrees Celsius/Fahrenheit). Absolute affine quantities do not add meaningfully; their difference is a pure delta.