thermo 2.1.0
Type-safe temperature handling library modeled after std::chrono
Loading...
Searching...
No Matches
thermo Namespace Reference

Temperature types and utilities. More...

Classes

class  delta
 A temperature difference with a representation and precision. More...
 
struct  is_delta
 Trait to detect delta specializations. More...
 
struct  is_delta< delta< Rep, Precision > >
 
class  temperature
 An absolute temperature on a given scale. More...
 

Typedefs

using delta_celsius = delta< int64_t >
 Delta with 1 degree precision (Celsius/Kelvin).
 
using delta_decicelsius = delta< int64_t, std::deci >
 Delta with 0.1 degree precision (Celsius/Kelvin).
 
using delta_millicelsius = delta< int64_t, std::milli >
 Delta with 0.001 degree precision (Celsius/Kelvin).
 
using delta_kelvin = delta< int64_t >
 Delta with 1 degree precision (Celsius/Kelvin).
 
using delta_decikelvin = delta< int64_t, std::deci >
 Delta with 0.1 degree precision (Celsius/Kelvin).
 
using delta_millikelvin = delta< int64_t, std::milli >
 Delta with 0.001 degree precision (Celsius/Kelvin).
 
using delta_fahrenheit = delta< int64_t, std::ratio< 5, 9 > >
 Delta with 1°F precision.
 
using delta_decifahrenheit = delta< int64_t, std::ratio< 5, 90 > >
 Delta with 0.1°F precision.
 
using delta_millifahrenheit = delta< int64_t, std::ratio< 5, 9000 > >
 Delta with 0.001°F precision.
 
using celsius = temperature< celsius_scale >
 Celsius with 1 degree precision.
 
using decicelsius = temperature< celsius_scale, delta< int64_t, std::deci > >
 Celsius with 0.1 degree precision.
 
using millicelsius = temperature< celsius_scale, delta< int64_t, std::milli > >
 Celsius with 0.001 degree precision.
 
using kelvin = temperature< kelvin_scale >
 Kelvin with 1 degree precision.
 
using decikelvin = temperature< kelvin_scale, delta< int64_t, std::deci > >
 Kelvin with 0.1 degree precision.
 
using millikelvin = temperature< kelvin_scale, delta< int64_t, std::milli > >
 Kelvin with 0.001 degree precision.
 
using fahrenheit = temperature< fahrenheit_scale, delta< int64_t, std::ratio< 5, 9 > > >
 Fahrenheit with 1 degree precision.
 
using decifahrenheit = temperature< fahrenheit_scale, delta< int64_t, std::ratio< 5, 90 > > >
 Fahrenheit with 0.1 degree precision.
 
using millifahrenheit = temperature< fahrenheit_scale, delta< int64_t, std::ratio< 5, 9000 > > >
 Fahrenheit with 0.001 degree precision.
 

Functions

template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta delta_cast (const delta< Rep, Precision > &d)
 Converts a delta to a different precision or representation.
 
template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta ceil (const delta< Rep, Precision > &d)
 Rounds a delta up to the nearest representable value in the target precision.
 
template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta floor (const delta< Rep, Precision > &d)
 Rounds a delta down to the nearest representable value in the target precision.
 
template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta trunc (const delta< Rep, Precision > &d)
 Rounds a delta toward zero to the nearest representable value in the target precision.
 
template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta round (const delta< Rep, Precision > &d)
 Rounds a delta to the nearest representable value in the target precision.
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator+ (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs) -> std::common_type_t< delta< Rep1, Precision1 >, delta< Rep2, Precision2 > >
 Returns the sum of two deltas.
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator- (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs) -> std::common_type_t< delta< Rep1, Precision1 >, delta< Rep2, Precision2 > >
 Returns the difference of two deltas.
 
template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator* (const delta< Rep1, Precision > &d, const Rep2 &r) -> delta< std::common_type_t< Rep1, Rep2 >, Precision >
 Multiplies a delta by a scalar.
 
template<typename Rep1 , typename Rep2 , typename Precision >
requires not_delta<Rep1> && std::convertible_to<const Rep1&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator* (const Rep1 &r, const delta< Rep2, Precision > &d) -> delta< std::common_type_t< Rep1, Rep2 >, Precision >
 Multiplies a scalar by a delta.
 
template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator/ (const delta< Rep1, Precision > &d, const Rep2 &s) -> delta< std::common_type_t< Rep1, Rep2 >, Precision >
 Divides a delta by a scalar.
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator/ (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs) -> std::common_type_t< Rep1, Rep2 >
 Divides two deltas, returning a scalar.
 
template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> && (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto operator% (const delta< Rep1, Precision > &d, const Rep2 &s) -> delta< std::common_type_t< Rep1, Rep2 >, Precision >
 Returns the remainder of dividing a delta by a scalar.
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto operator% (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs) -> std::common_type_t< delta< Rep1, Precision1 >, delta< Rep2, Precision2 > >
 Returns the remainder of dividing two deltas.
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr bool operator== (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs)
 
template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto operator<=> (const delta< Rep1, Precision1 > &lhs, const delta< Rep2, Precision2 > &rhs)
 
template<typename Rep , typename Precision >
requires (!treat_as_inexact_v<Rep>)
std::string to_string (const delta< Rep, Precision > &d)
 Renders a delta as its exact count with a precision-qualified unit, e.g.
 
template<typename ToTemp , typename Scale , typename Delta >
constexpr ToTemp temperature_cast (const temperature< Scale, Delta > &t)
 Converts a temperature to a different scale or precision.
 
template<typename Scale , typename Delta1 , typename Delta2 >
constexpr auto operator+ (const temperature< Scale, Delta1 > &lhs, const temperature< Scale, Delta2 > &rhs) -> temperature< Scale, std::common_type_t< Delta1, Delta2 > >
 Adds two temperatures on the same scale.
 
template<typename Scale , typename Delta1 , typename Delta2 >
constexpr auto operator- (const temperature< Scale, Delta1 > &lhs, const temperature< Scale, Delta2 > &rhs) -> temperature< Scale, std::common_type_t< Delta1, Delta2 > >
 Subtracts two temperatures on the same scale.
 
template<typename Scale , typename Delta1 , typename Delta2 >
constexpr auto difference (const temperature< Scale, Delta1 > &lhs, const temperature< Scale, Delta2 > &rhs) -> std::common_type_t< Delta1, Delta2 >
 Returns the difference between two temperatures as a delta.
 
template<typename Scale , typename Delta1 , typename Rep2 , typename Precision2 >
constexpr auto operator+ (const temperature< Scale, Delta1 > &t, const delta< Rep2, Precision2 > &d) -> temperature< Scale, std::common_type_t< Delta1, delta< Rep2, Precision2 > > >
 Adds a delta to a temperature.
 
template<typename Rep1 , typename Precision1 , typename Scale , typename Delta2 >
constexpr auto operator+ (const delta< Rep1, Precision1 > &d, const temperature< Scale, Delta2 > &t) -> temperature< Scale, std::common_type_t< delta< Rep1, Precision1 >, Delta2 > >
 Adds a temperature to a delta.
 
template<typename Scale , typename Delta1 , typename Rep2 , typename Precision2 >
constexpr auto operator- (const temperature< Scale, Delta1 > &t, const delta< Rep2, Precision2 > &d) -> temperature< Scale, std::common_type_t< Delta1, delta< Rep2, Precision2 > > >
 Subtracts a delta from a temperature.
 
template<typename Scale , typename Delta1 , typename Delta2 >
constexpr bool operator== (const temperature< Scale, Delta1 > &lhs, const temperature< Scale, Delta2 > &rhs)
 
template<typename Scale , typename Delta1 , typename Delta2 >
requires std::three_way_comparable<std::common_type_t<typename Delta1::rep, typename Delta2::rep>>
constexpr auto operator<=> (const temperature< Scale, Delta1 > &lhs, const temperature< Scale, Delta2 > &rhs)
 
template<typename Scale , typename Rep , typename Precision >
requires (!treat_as_inexact_v<Rep>)
std::string to_string (const temperature< Scale, delta< Rep, Precision > > &t)
 Renders a temperature as its exact count with a precision-qualified unit, e.g.
 

Detailed Description

Temperature types and utilities.

This library provides type-safe temperature handling with support for multiple scales (Celsius, Kelvin, Fahrenheit) and precisions, following the design of std::chrono. It distinguishes between absolute temperatures and temperature differences (deltas).

Typedef Documentation

◆ celsius

Celsius with 1 degree precision.

Definition at line 885 of file thermo.hpp.

◆ decicelsius

Celsius with 0.1 degree precision.

Definition at line 887 of file thermo.hpp.

◆ decifahrenheit

Fahrenheit with 0.1 degree precision.

Definition at line 899 of file thermo.hpp.

◆ decikelvin

Kelvin with 0.1 degree precision.

Definition at line 893 of file thermo.hpp.

◆ delta_celsius

Delta with 1 degree precision (Celsius/Kelvin).

Definition at line 463 of file thermo.hpp.

◆ delta_decicelsius

Delta with 0.1 degree precision (Celsius/Kelvin).

Definition at line 465 of file thermo.hpp.

◆ delta_decifahrenheit

Delta with 0.1°F precision.

Definition at line 477 of file thermo.hpp.

◆ delta_decikelvin

Delta with 0.1 degree precision (Celsius/Kelvin).

Definition at line 471 of file thermo.hpp.

◆ delta_fahrenheit

Delta with 1°F precision.

Definition at line 475 of file thermo.hpp.

◆ delta_kelvin

Delta with 1 degree precision (Celsius/Kelvin).

Definition at line 469 of file thermo.hpp.

◆ delta_millicelsius

Delta with 0.001 degree precision (Celsius/Kelvin).

Definition at line 467 of file thermo.hpp.

◆ delta_millifahrenheit

Delta with 0.001°F precision.

Definition at line 479 of file thermo.hpp.

◆ delta_millikelvin

Delta with 0.001 degree precision (Celsius/Kelvin).

Definition at line 473 of file thermo.hpp.

◆ fahrenheit

Fahrenheit with 1 degree precision.

Definition at line 897 of file thermo.hpp.

◆ kelvin

Kelvin with 1 degree precision.

Definition at line 891 of file thermo.hpp.

◆ millicelsius

Celsius with 0.001 degree precision.

Definition at line 889 of file thermo.hpp.

◆ millifahrenheit

Fahrenheit with 0.001 degree precision.

Definition at line 901 of file thermo.hpp.

◆ millikelvin

Kelvin with 0.001 degree precision.

Definition at line 895 of file thermo.hpp.

Function Documentation

◆ ceil()

constexpr ToDelta thermo::ceil ( const delta< Rep, Precision > &  d)
constexpr

Rounds a delta up to the nearest representable value in the target precision.

Returns the smallest value of type ToDelta that is greater than or equal to d. When converting to the same or finer precision, returns the exact conversion.

Template Parameters
ToDeltaTarget delta type.
RepSource representation type.
PrecisionSource precision.
Parameters
dThe delta to round.
Returns
The rounded delta.

Definition at line 288 of file thermo.hpp.

References delta_cast().

◆ delta_cast()

template<typename ToDelta , typename Rep , typename Precision >
constexpr ToDelta thermo::delta_cast ( const delta< Rep, Precision > &  d)
constexpr

Converts a delta to a different precision or representation.

Template Parameters
ToDeltaThe target delta type.
RepSource representation type.
PrecisionSource precision.
Parameters
dThe delta to convert.
Returns
The converted delta.

Definition at line 252 of file thermo.hpp.

References thermo::delta< Rep, Precision >::count().

Referenced by ceil(), difference(), floor(), operator%(), operator%(), operator*(), operator*(), operator+(), operator+(), operator+(), operator+(), thermo::temperature< Scale, Delta >::operator+=(), operator-(), operator-(), operator-(), thermo::temperature< Scale, Delta >::operator-=(), operator/(), operator/(), operator<=>(), operator<=>(), operator==(), operator==(), round(), temperature_cast(), to_string(), to_string(), and trunc().

◆ difference()

constexpr auto thermo::difference ( const temperature< Scale, Delta1 > &  lhs,
const temperature< Scale, Delta2 > &  rhs 
) -> std::common_type_t<Delta1, Delta2>
constexpr

Returns the difference between two temperatures as a delta.

Parameters
lhsFirst temperature.
rhsSecond temperature.
Returns
lhs - rhs as a delta.

Definition at line 844 of file thermo.hpp.

References delta_cast().

◆ floor()

constexpr ToDelta thermo::floor ( const delta< Rep, Precision > &  d)
constexpr

Rounds a delta down to the nearest representable value in the target precision.

Returns the largest value of type ToDelta that is less than or equal to d. When converting to the same or finer precision, returns the exact conversion.

Template Parameters
ToDeltaTarget delta type.
RepSource representation type.
PrecisionSource precision.
Parameters
dThe delta to round.
Returns
The rounded delta.

Definition at line 309 of file thermo.hpp.

References delta_cast().

◆ operator%() [1/2]

template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> && (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto thermo::operator% ( const delta< Rep1, Precision > &  d,
const Rep2 s 
) -> delta<std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Returns the remainder of dividing a delta by a scalar.

Definition at line 434 of file thermo.hpp.

References delta_cast().

◆ operator%() [2/2]

Returns the remainder of dividing two deltas.

Definition at line 443 of file thermo.hpp.

References delta_cast().

◆ operator*() [1/2]

template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto thermo::operator* ( const delta< Rep1, Precision > &  d,
const Rep2 r 
) -> delta<std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Multiplies a delta by a scalar.

Definition at line 399 of file thermo.hpp.

References delta_cast().

◆ operator*() [2/2]

template<typename Rep1 , typename Rep2 , typename Precision >
requires not_delta<Rep1> && std::convertible_to<const Rep1&, std::common_type_t<Rep1, Rep2>>
constexpr auto thermo::operator* ( const Rep1 r,
const delta< Rep2, Precision > &  d 
) -> delta<std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Multiplies a scalar by a delta.

Definition at line 408 of file thermo.hpp.

References delta_cast().

◆ operator+() [1/4]

Adds a temperature to a delta.

Definition at line 860 of file thermo.hpp.

References delta_cast().

◆ operator+() [2/4]

Returns the sum of two deltas.

Definition at line 382 of file thermo.hpp.

References delta_cast().

◆ operator+() [3/4]

constexpr auto thermo::operator+ ( const temperature< Scale, Delta1 > &  lhs,
const temperature< Scale, Delta2 > &  rhs 
) -> temperature<Scale, std::common_type_t<Delta1, Delta2>>
constexpr

Adds two temperatures on the same scale.

Definition at line 821 of file thermo.hpp.

References delta_cast().

◆ operator+() [4/4]

Adds a delta to a temperature.

Definition at line 852 of file thermo.hpp.

References delta_cast().

◆ operator-() [1/3]

Returns the difference of two deltas.

Definition at line 390 of file thermo.hpp.

References delta_cast().

◆ operator-() [2/3]

constexpr auto thermo::operator- ( const temperature< Scale, Delta1 > &  lhs,
const temperature< Scale, Delta2 > &  rhs 
) -> temperature<Scale, std::common_type_t<Delta1, Delta2>>
constexpr

Subtracts two temperatures on the same scale.

Definition at line 829 of file thermo.hpp.

References delta_cast().

◆ operator-() [3/3]

Subtracts a delta from a temperature.

Definition at line 867 of file thermo.hpp.

References delta_cast().

◆ operator/() [1/2]

template<typename Rep1 , typename Precision , typename Rep2 >
requires not_delta<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto thermo::operator/ ( const delta< Rep1, Precision > &  d,
const Rep2 s 
) -> delta<std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Divides a delta by a scalar.

Definition at line 416 of file thermo.hpp.

References delta_cast().

◆ operator/() [2/2]

constexpr auto thermo::operator/ ( const delta< Rep1, Precision1 > &  lhs,
const delta< Rep2, Precision2 > &  rhs 
) -> std::common_type_t<Rep1, Rep2>
constexpr

Divides two deltas, returning a scalar.

Definition at line 424 of file thermo.hpp.

References thermo::delta< Rep, Precision >::count(), and delta_cast().

◆ operator<=>() [1/2]

template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto thermo::operator<=> ( const delta< Rep1, Precision1 > &  lhs,
const delta< Rep2, Precision2 > &  rhs 
)
constexpr

Definition at line 457 of file thermo.hpp.

References thermo::delta< Rep, Precision >::count(), and delta_cast().

◆ operator<=>() [2/2]

template<typename Scale , typename Delta1 , typename Delta2 >
requires std::three_way_comparable<std::common_type_t<typename Delta1::rep, typename Delta2::rep>>
constexpr auto thermo::operator<=> ( const temperature< Scale, Delta1 > &  lhs,
const temperature< Scale, Delta2 > &  rhs 
)
constexpr

Definition at line 880 of file thermo.hpp.

References delta_cast().

◆ operator==() [1/2]

◆ operator==() [2/2]

Definition at line 874 of file thermo.hpp.

References delta_cast().

◆ round()

constexpr ToDelta thermo::round ( const delta< Rep, Precision > &  d)
constexpr

Rounds a delta to the nearest representable value in the target precision.

Returns the value of type ToDelta that is nearest to d. When exactly halfway between two values, rounds away from zero. When converting to the same or finer precision, returns the exact conversion.

Template Parameters
ToDeltaTarget delta type.
RepSource representation type.
PrecisionSource precision.
Parameters
dThe delta to round.
Returns
The rounded delta.

Definition at line 348 of file thermo.hpp.

References delta_cast().

◆ temperature_cast()

constexpr ToTemp thermo::temperature_cast ( const temperature< Scale, Delta > &  t)
constexpr

Converts a temperature to a different scale or precision.

Template Parameters
ToTempThe target temperature type.
ScaleSource scale.
DeltaSource delta type.
Parameters
tThe temperature to convert.
Returns
The converted temperature.

Definition at line 779 of file thermo.hpp.

References delta_cast().

◆ to_string() [1/2]

std::string thermo::to_string ( const delta< Rep, Precision > &  d)

Renders a delta as its exact count with a precision-qualified unit, e.g.

to_string(delta_millicelsius(1500)) == "1500Δm°C".

Definition at line 544 of file thermo.hpp.

References delta_cast().

◆ to_string() [2/2]

std::string thermo::to_string ( const temperature< Scale, delta< Rep, Precision > > &  t)

Renders a temperature as its exact count with a precision-qualified unit, e.g.

to_string(millicelsius(22500)) == "22500m°C".

Definition at line 909 of file thermo.hpp.

References delta_cast().

◆ trunc()

constexpr ToDelta thermo::trunc ( const delta< Rep, Precision > &  d)
constexpr

Rounds a delta toward zero to the nearest representable value in the target precision.

Returns the value of type ToDelta that is closest to zero. When converting to the same or finer precision, returns the exact conversion.

Template Parameters
ToDeltaTarget delta type.
RepSource representation type.
PrecisionSource precision.
Parameters
dThe delta to round.
Returns
The rounded delta.

Definition at line 330 of file thermo.hpp.

References delta_cast().