thermo 1.0.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, 900 > >
 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, 900 > > >
 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)
 
std::string to_string (delta< int64_t > d)
 
std::string to_string (delta< int64_t, std::deci > d)
 
std::string to_string (delta< int64_t, std::milli > d)
 
std::string to_string (delta_fahrenheit d)
 
std::string to_string (delta_decifahrenheit d)
 
std::string to_string (delta_millifahrenheit d)
 
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)
 
std::string to_string (celsius t)
 
std::string to_string (decicelsius t)
 
std::string to_string (kelvin t)
 
std::string to_string (fahrenheit t)
 
std::string to_string (decifahrenheit t)
 
std::string to_string (millifahrenheit t)
 

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 811 of file thermo.hpp.

◆ decicelsius

Celsius with 0.1 degree precision.

Definition at line 813 of file thermo.hpp.

◆ decifahrenheit

Fahrenheit with 0.1 degree precision.

Definition at line 825 of file thermo.hpp.

◆ decikelvin

Kelvin with 0.1 degree precision.

Definition at line 819 of file thermo.hpp.

◆ delta_celsius

Delta with 1 degree precision (Celsius/Kelvin).

Definition at line 462 of file thermo.hpp.

◆ delta_decicelsius

Delta with 0.1 degree precision (Celsius/Kelvin).

Definition at line 464 of file thermo.hpp.

◆ delta_decifahrenheit

Delta with 0.1°F precision.

Definition at line 476 of file thermo.hpp.

◆ delta_decikelvin

Delta with 0.1 degree precision (Celsius/Kelvin).

Definition at line 470 of file thermo.hpp.

◆ delta_fahrenheit

Delta with 1°F precision.

Definition at line 474 of file thermo.hpp.

◆ delta_kelvin

Delta with 1 degree precision (Celsius/Kelvin).

Definition at line 468 of file thermo.hpp.

◆ delta_millicelsius

Delta with 0.001 degree precision (Celsius/Kelvin).

Definition at line 466 of file thermo.hpp.

◆ delta_millifahrenheit

Delta with 0.001°F precision.

Definition at line 478 of file thermo.hpp.

◆ delta_millikelvin

Delta with 0.001 degree precision (Celsius/Kelvin).

Definition at line 472 of file thermo.hpp.

◆ fahrenheit

Fahrenheit with 1 degree precision.

Definition at line 823 of file thermo.hpp.

◆ kelvin

Kelvin with 1 degree precision.

Definition at line 817 of file thermo.hpp.

◆ millicelsius

Celsius with 0.001 degree precision.

Definition at line 815 of file thermo.hpp.

◆ millifahrenheit

Fahrenheit with 0.001 degree precision.

Definition at line 827 of file thermo.hpp.

◆ millikelvin

Kelvin with 0.001 degree precision.

Definition at line 821 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 287 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 251 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(), to_string(), to_string(), to_string(), to_string(), to_string(), to_string(), to_string(), to_string(), 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 770 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 308 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 433 of file thermo.hpp.

References delta_cast().

◆ operator%() [2/2]

Returns the remainder of dividing two deltas.

Definition at line 442 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 398 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 407 of file thermo.hpp.

References delta_cast().

◆ operator+() [1/4]

Adds a temperature to a delta.

Definition at line 786 of file thermo.hpp.

References delta_cast().

◆ operator+() [2/4]

Returns the sum of two deltas.

Definition at line 381 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 747 of file thermo.hpp.

References delta_cast().

◆ operator+() [4/4]

Adds a delta to a temperature.

Definition at line 778 of file thermo.hpp.

References delta_cast().

◆ operator-() [1/3]

Returns the difference of two deltas.

Definition at line 389 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 755 of file thermo.hpp.

References delta_cast().

◆ operator-() [3/3]

Subtracts a delta from a temperature.

Definition at line 793 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 415 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 423 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 456 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 806 of file thermo.hpp.

References delta_cast().

◆ operator==() [1/2]

◆ operator==() [2/2]

Definition at line 800 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 347 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 705 of file thermo.hpp.

References delta_cast().

◆ to_string() [1/12]

std::string thermo::to_string ( celsius  t)
inline

Definition at line 829 of file thermo.hpp.

References delta_cast().

◆ to_string() [2/12]

std::string thermo::to_string ( decicelsius  t)
inline

Definition at line 833 of file thermo.hpp.

References delta_cast().

◆ to_string() [3/12]

std::string thermo::to_string ( decifahrenheit  t)
inline

Definition at line 857 of file thermo.hpp.

References delta_cast().

◆ to_string() [4/12]

std::string thermo::to_string ( delta< int64_t d)
inline

Definition at line 480 of file thermo.hpp.

References delta_cast().

◆ to_string() [5/12]

std::string thermo::to_string ( delta< int64_t, std::deci >  d)
inline

Definition at line 484 of file thermo.hpp.

References delta_cast().

◆ to_string() [6/12]

std::string thermo::to_string ( delta< int64_t, std::milli >  d)
inline

Definition at line 488 of file thermo.hpp.

References delta_cast().

◆ to_string() [7/12]

std::string thermo::to_string ( delta_decifahrenheit  d)
inline

Definition at line 496 of file thermo.hpp.

References delta_cast().

◆ to_string() [8/12]

std::string thermo::to_string ( delta_fahrenheit  d)
inline

Definition at line 492 of file thermo.hpp.

References delta_cast().

◆ to_string() [9/12]

std::string thermo::to_string ( delta_millifahrenheit  d)
inline

Definition at line 500 of file thermo.hpp.

References delta_cast().

◆ to_string() [10/12]

std::string thermo::to_string ( fahrenheit  t)
inline

Definition at line 853 of file thermo.hpp.

References delta_cast().

◆ to_string() [11/12]

std::string thermo::to_string ( kelvin  t)
inline

Definition at line 841 of file thermo.hpp.

References delta_cast().

◆ to_string() [12/12]

std::string thermo::to_string ( millifahrenheit  t)
inline

Definition at line 861 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 329 of file thermo.hpp.

References delta_cast().