units_unit_t(3)

units::unit_t< Units, T, NonLinearScale >(3) Unit Conversion and Dimensional Analysis Library units::unit_t< Units, T, NonLinearScale >(3)

NAME

units::unit_t< Units, T, NonLinearScale > - Container for values which represent quantities of a given unit.

SYNOPSIS

#include <units.h>

Inherits units::linear_scale< double >, and units::detail::_unit_t.

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

Public Member Functions inherited from units::linear_scale< double >
constexpr linear_scale ()=default
default constructor. linear_scale & operator= (const linear_scale &)=default
constexpr double operator() () const noexcept
returns value.

Protected Types


using nls = NonLinearScale<T>

Additional Inherited Members

Public Attributes inherited from units::linear_scale< double >
double m_value
linearized value.

Detailed Description

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale>

class units::unit_t< Units, T, NonLinearScale >"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():

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

.

Template Parameters

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.

See also

  • length unit containers
  • mass unit containers
  • time unit containers
  • angle unit containers
  • current unit containers
  • temperature unit containers
  • substance unit containers
  • luminous intensity unit containers
  • solid angle unit containers
  • frequency unit containers
  • velocity unit containers
  • angular velocity unit containers
  • acceleration unit containers
jerk unit containers
  • force unit containers
  • pressure unit containers
  • charge unit containers
  • energy unit containers
  • power unit containers
  • voltage unit containers
  • capacitance unit containers
  • impedance unit containers
  • magnetic flux unit containers
  • magnetic field strength unit containers
  • inductance unit containers
  • luminous flux unit containers
  • illuminance unit containers
  • radiation unit containers
  • torque unit containers
  • area unit containers
  • volume unit containers
  • density unit containers
  • concentration unit containers
  • constant unit containers

Constructor & Destructor Documentation

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class... Args> units::unit_t< Units, T, NonLinearScale >::unit_t (const T value, const Args &... args) [inline], [explicit], [constexpr], [noexcept]

constructor constructs a new unit_t using the non-linear scale's constructor.

Parameters

value unit value magnitude.
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.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class Ty, class = typename std::enable_if<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>::type> units::unit_t< Units, T, NonLinearScale >::unit_t (const Ty value) [inline], [constexpr], [noexcept]

constructor enable implicit conversions from T types ONLY for linear scalar units

Parameters

value value of the unit_t

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class Rep, class Period, class = std::enable_if_t<std::is_arithmetic<Rep>::value && traits::is_ratio<Period>::value>> units::unit_t< Units, T, NonLinearScale >::unit_t (const std::chrono::duration< Rep, Period > & value) [inline], [constexpr], [noexcept]

chrono constructor enable implicit conversions from std::chrono::duration types ONLY for time units

Parameters

value value of the unit_t

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> units::unit_t< Units, T, NonLinearScale >::unit_t (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) [inline], [constexpr], [noexcept]

copy constructor (converting) performs implicit unit conversions if required.

Parameters

rhs unit to copy.

Member Function Documentation

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class U> unit_t< U > units::unit_t< Units, T, NonLinearScale >::convert () const [inline], [constexpr], [noexcept]

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.

Template Parameters

U unit (not unit_t) to convert to

Returns

a unit container with the specified units containing the equivalent value to *this.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<typename U = Units, std::enable_if_t< units::traits::is_convertible_unit< U, unit< std::ratio< 1 >, category::time_unit > >::value, int > = 0> units::unit_t< Units, T, NonLinearScale >::operator std::chrono::nanoseconds () const [inline], [constexpr], [noexcept]

chrono implicit type conversion. only enabled for time unit types.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class Ty, std::enable_if_t<!traits::is_dimensionless_unit< Units >::value &&std::is_arithmetic< Ty >::value, int > = 0> units::unit_t< Units, T, NonLinearScale >::operator Ty () const [inline], [explicit], [constexpr], [noexcept]

explicit type conversion. only enabled for non-dimensionless unit types.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class Ty, std::enable_if_t< traits::is_dimensionless_unit< Units >::value &&std::is_arithmetic< Ty >::value, int > = 0> units::unit_t< Units, T, NonLinearScale >::operator Ty () const [inline], [constexpr], [noexcept]

implicit type conversion. only enabled for scalar unit types.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> bool units::unit_t< Units, T, NonLinearScale >::operator!= (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

inequality compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this is not equal to the value of rhs.

Note

This may not be suitable for all applications when the underlying_type of unit_t is a double.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> bool units::unit_t< Units, T, NonLinearScale >::operator< (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

less-than compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this is less than the value of rhs

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> bool units::unit_t< Units, T, NonLinearScale >::operator<= (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

less-than or equal compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this is less than or equal to the value of rhs

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class Ty, class = std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value>> unit_t & units::unit_t< Units, T, NonLinearScale >::operator= (const Ty & rhs) [inline], [noexcept]

assignment performs implicit conversions from built-in types ONLY for scalar units

Parameters

rhs value to copy.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> unit_t & units::unit_t< Units, T, NonLinearScale >::operator= (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) [inline], [noexcept]

assignment performs implicit unit conversions if required

Parameters

rhs unit to copy.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> 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> bool units::unit_t< Units, T, NonLinearScale >::operator== (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

equality compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this exactly equal to the value of rhs.

Note

This may not be suitable for all applications when the underlying_type of unit_t is a double.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> bool units::unit_t< Units, T, NonLinearScale >::operator> (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

greater-than compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this is greater than the value of rhs

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<class UnitsRhs, typename Ty, template< typename > class NlsRhs> bool units::unit_t< Units, T, NonLinearScale >::operator>= (const unit_t< UnitsRhs, Ty, NlsRhs > & rhs) const [inline], [constexpr], [noexcept]

greater-than or equal compares the linearized value of two units. Performs unit conversions if necessary.

Parameters

rhs right-hand side unit for the comparison

Returns

true IFF the value of this is greater than or equal to the value of rhs

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>> Ty units::unit_t< Units, T, NonLinearScale >::to () const [inline], [constexpr], [noexcept]

unit value

Returns

value of the unit converted to an arithmetic, non-safe type.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> template<typename Ty, class = std::enable_if_t<std::is_arithmetic<Ty>::value>> Ty units::unit_t< Units, T, NonLinearScale >::toLinearized () const [inline], [constexpr], [noexcept]

linearized unit value

Returns

linearized value of unit which has a non-linear scale. For unit_t types with linear scales, this is equivalent to value.

template<class Units, typename T = double, template< typename > class NonLinearScale = linear_scale> underlying_type units::unit_t< Units, T, NonLinearScale >::value () const [inline], [constexpr], [noexcept]

unit value

Returns

value of the unit in it's underlying, non-safe type.

Author

Generated automatically by Doxygen for Unit Conversion and Dimensional Analysis Library from the source code.

Wed Feb 11 2026 09:38:34 Version 2.3.0