Container for values which represent quantities of a given unit. More...
#include <units/base.h>
Public Types | |
typedef NonLinearScale< T > | non_linear_scale_type |
Type of the non-linear scale of the unit_t (e.g. linear_scale) | |
typedef T | underlying_type |
Type of the underlying storage of the unit_t (e.g. double) | |
typedef T | value_type |
Synonym for underlying type. May be removed in future versions. Prefer underlying_type. | |
typedef Units | unit_type |
Type of unit the unit_t represents (e.g. meters) | |
Public Member Functions | |
constexpr | unit_t ()=default |
default constructor. | |
template<class... Args> | |
constexpr | unit_t (const T value, const Args &... args) noexcept |
constructor | |
template<class Ty , class = typename std::enable_if<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>::type> | |
constexpr | unit_t (const Ty value) noexcept |
constructor | |
template<class Rep , class Period , class = std::enable_if_t<std::is_arithmetic<Rep>::value && traits::is_ratio<Period>::value>> | |
constexpr | unit_t (const std::chrono::duration< Rep, Period > &value) noexcept |
chrono constructor | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr | unit_t (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept |
copy constructor (converting) | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
unit_t & | operator= (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) noexcept |
assignment | |
template<class Ty , class = std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>> | |
unit_t & | operator= (const Ty &rhs) noexcept |
assignment | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr bool | operator< (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
less-than | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr bool | operator<= (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
less-than or equal | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr bool | operator> (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
greater-than | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr bool | operator>= (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
greater-than or equal | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs, std::enable_if_t< std::is_floating_point< T >::value||std::is_floating_point< Ty >::value, int > = 0> | |
constexpr bool | operator== (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
equality | |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs, std::enable_if_t< std::is_integral< T >::value &&std::is_integral< Ty >::value, int > = 0> | |
constexpr bool | operator== (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
template<class UnitsRhs , typename Ty , template< typename > class NlsRhs> | |
constexpr bool | operator!= (const unit_t< UnitsRhs, Ty, NlsRhs > &rhs) const noexcept |
inequality | |
constexpr underlying_type | value () const noexcept |
unit value | |
template<typename Ty , class = std::enable_if_t<std::is_arithmetic<Ty>::value>> | |
constexpr Ty | to () const noexcept |
unit value | |
template<typename Ty , class = std::enable_if_t<std::is_arithmetic<Ty>::value>> | |
constexpr Ty | toLinearized () const noexcept |
linearized unit value | |
template<class U > | |
constexpr unit_t< U > | convert () const noexcept |
conversion | |
template<class Ty , std::enable_if_t< traits::is_dimensionless_unit< Units >::value &&std::is_arithmetic< Ty >::value, int > = 0> | |
constexpr | operator Ty () const noexcept |
implicit type conversion. | |
template<class Ty , std::enable_if_t<!traits::is_dimensionless_unit< Units >::value &&std::is_arithmetic< Ty >::value, int > = 0> | |
constexpr | operator Ty () const noexcept |
explicit type conversion. | |
template<typename U = Units, std::enable_if_t< units::traits::is_convertible_unit< U, unit< std::ratio< 1 >, category::time_unit > >::value, int > = 0> | |
constexpr | operator std::chrono::nanoseconds () const noexcept |
chrono implicit type conversion. | |
constexpr const char * | name () const noexcept |
returns the unit name | |
constexpr const char * | abbreviation () const noexcept |
returns the unit abbreviation | |
![]() | |
constexpr | linear_scale ()=default |
default constructor. | |
constexpr | linear_scale (const linear_scale &)=default |
constexpr | linear_scale (const UNIT_LIB_DEFAULT_TYPE &value, Args &&...) noexcept |
constructor. | |
~linear_scale ()=default | |
linear_scale & | operator= (const linear_scale &)=default |
constexpr UNIT_LIB_DEFAULT_TYPE | operator() () const noexcept |
returns value. | |
Protected Types | |
using | nls = NonLinearScale<T> |
Friends | |
template<class U , typename Ty , template< typename > class Nlt> | |
class | unit_t |
Additional Inherited Members | |
![]() | |
UNIT_LIB_DEFAULT_TYPE | m_value |
linearized value. | |
Container for values which represent quantities of a given unit.
Stores a value which represents a quantity in the given units. Unit containers (except scalar values) are not convertible to built-in c++ types, in order to provide type safety in dimensional analysis. Unit containers are implicitly convertible to other compatible unit container types. Unit containers support various types of arithmetic operations, depending on their scale type.
The value of a unit_t
can only be changed on construction, or by assignment from another unit_t
type. If necessary, the underlying value can be accessed using operator()
:
.
Units | unit tag for which type of units the unit_t represents (e.g. meters) |
T | underlying type of the storage. Defaults to double. |
NonLinearScale | optional 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. Non-linear scales must adhere to the non-linear-scale concept, i.e. is_nonlinear_scale<...>::value must be true . |
|
protected |
NonLinearScale<T> units::unit_t< Units, T, NonLinearScale >::non_linear_scale_type |
Type of the non-linear scale of the unit_t (e.g. linear_scale)
T units::unit_t< Units, T, NonLinearScale >::underlying_type |
Type of the underlying storage of the unit_t (e.g. double)
Units units::unit_t< Units, T, NonLinearScale >::unit_type |
Type of unit
the unit_t
represents (e.g. meters)
T units::unit_t< Units, T, NonLinearScale >::value_type |
Synonym for underlying type. May be removed in future versions. Prefer underlying_type.
|
constexprdefault |
default constructor.
|
inlineexplicitconstexprnoexcept |
constructor
constructs a new unit_t using the non-linear scale's constructor.
[in] | value | unit value magnitude. |
[in] | args | additional constructor arguments are forwarded to the non-linear scale constructor. Which args are required depends on which scale is used. For the default (linear) scale, no additional args are necessary. |
|
inlineconstexprnoexcept |
constructor
enable implicit conversions from T types ONLY for linear scalar units
[in] | value | value of the unit_t |
|
inlineconstexprnoexcept |
chrono constructor
enable implicit conversions from std::chrono::duration types ONLY for time units
[in] | value | value of the unit_t |
|
inlineconstexprnoexcept |
copy constructor (converting)
performs implicit unit conversions if required.
[in] | rhs | unit to copy. |
|
inlineconstexprnoexcept |
returns the unit abbreviation
|
inlineconstexprnoexcept |
conversion
Converts to a different unit container. Units can be converted to other containers implicitly, but this can be used in cases where explicit notation of a conversion is beneficial, or where an r-value container is needed.
U | unit (not unit_t) to convert to |
|
inlineconstexprnoexcept |
returns the unit name
|
inlineconstexprnoexcept |
chrono implicit type conversion.
only enabled for time unit types.
|
inlineconstexprnoexcept |
implicit type conversion.
only enabled for scalar unit types.
|
inlineexplicitconstexprnoexcept |
explicit type conversion.
only enabled for non-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 |
this
is not equal to the value of rhs.
|
inlineconstexprnoexcept |
less-than
compares the linearized value of two units. Performs unit conversions if necessary.
[in] | rhs | right-hand side unit for the comparison |
this
is less than the value of rhs
|
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 |
this
is less than or equal to the value of rhs
|
inlinenoexcept |
assignment
performs implicit conversions from built-in types ONLY for scalar units
[in] | rhs | value to copy. |
|
inlinenoexcept |
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 |
this
exactly equal to the value of rhs.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
greater-than
compares the linearized value of two units. Performs unit conversions if necessary.
[in] | rhs | right-hand side unit for the comparison |
this
is greater than the value of rhs
|
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 |
this
is greater than or equal to the value of rhs
|
inlineconstexprnoexcept |
unit value
|
inlineconstexprnoexcept |
linearized unit value
unit_t
types with linear scales, this is equivalent to value
.
|
inlineconstexprnoexcept |
unit value
|
friend |