mirror of
https://github.com/mpusz/mp-units.git
synced 2025-06-25 01:01:33 +02:00
@ -261,7 +261,7 @@ This introduces an additional type-safety.
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::usc::unit_symbols;
|
||||
|
||||
quantity_point temp = absolute<deg_C>(20.);
|
||||
quantity_point temp = point<deg_C>(20.);
|
||||
std::println("Temperature: {} ({})",
|
||||
temp.quantity_from_zero(),
|
||||
temp.in(deg_F).quantity_from_zero());
|
||||
@ -282,7 +282,7 @@ This introduces an additional type-safety.
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::usc::unit_symbols;
|
||||
|
||||
quantity_point temp = absolute<deg_C>(20.);
|
||||
quantity_point temp = point<deg_C>(20.);
|
||||
std::println("Temperature: {} ({})",
|
||||
temp.quantity_from_zero(),
|
||||
temp.in(deg_F).quantity_from_zero());
|
||||
|
@ -118,7 +118,7 @@ scale zeroth point using the following rules:
|
||||
- otherwise, an instantiation of `zeroth_point_origin<QuantitySpec>` is being used which
|
||||
provides a well-established zeroth point for a specific quantity type.
|
||||
|
||||
Quantity points with default point origins may be constructed with the `absolute` construction
|
||||
Quantity points with default point origins may be constructed with the `point` construction
|
||||
helper or forcing an explicit conversion from the `quantity`:
|
||||
|
||||
```cpp
|
||||
@ -128,9 +128,9 @@ helper or forcing an explicit conversion from the `quantity`:
|
||||
quantity_point qp4(42 * m);
|
||||
quantity_point qp5(42 * K);
|
||||
quantity_point qp6(delta<deg_C>(42));
|
||||
quantity_point qp7 = absolute<m>(42);
|
||||
quantity_point qp8 = absolute<K>(42);
|
||||
quantity_point qp9 = absolute<deg_C>(42);
|
||||
quantity_point qp7 = point<m>(42);
|
||||
quantity_point qp8 = point<K>(42);
|
||||
quantity_point qp9 = point<deg_C>(42);
|
||||
```
|
||||
|
||||
!!! tip
|
||||
@ -149,7 +149,7 @@ for this domain.
|
||||
|
||||
```cpp
|
||||
quantity_point<isq::distance[si::metre]> qp1(100 * m);
|
||||
quantity_point<isq::distance[si::metre]> qp2 = absolute<m>(120);
|
||||
quantity_point<isq::distance[si::metre]> qp2 = point<m>(120);
|
||||
|
||||
assert(qp1.quantity_from_zero() == 100 * m);
|
||||
assert(qp2.quantity_from_zero() == 120 * m);
|
||||
@ -178,7 +178,7 @@ compatible:
|
||||
|
||||
```cpp
|
||||
quantity_point<si::metre> qp1{isq::distance(100 * m)};
|
||||
quantity_point<si::metre> qp2 = absolute<isq::height[m]>(120);
|
||||
quantity_point<si::metre> qp2 = point<isq::height[m]>(120);
|
||||
|
||||
assert(qp2.quantity_from(qp1) == 20 * m);
|
||||
assert(qp1.quantity_from(qp2) == -20 * m);
|
||||
@ -411,7 +411,7 @@ namespace si {
|
||||
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr auto zeroth_kelvin = absolute_zero;
|
||||
|
||||
inline constexpr struct ice_point final : relative_point_origin<absolute<milli<kelvin>>(273'150)}> {} ice_point;
|
||||
inline constexpr struct ice_point final : relative_point_origin<point<milli<kelvin>>(273'150)}> {} ice_point;
|
||||
inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
|
||||
}
|
||||
@ -419,7 +419,7 @@ inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
namespace usc {
|
||||
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final :
|
||||
relative_point_origin<absolute<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
|
||||
relative_point_origin<point<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
|
||||
|
||||
}
|
||||
```
|
||||
@ -471,7 +471,7 @@ choose from here. Depending on our needs or tastes, we can:
|
||||
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q1 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
|
||||
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q2{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
|
||||
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q3{delta<deg_C>(20.5)};
|
||||
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q4 = absolute<deg_C>(20.5);
|
||||
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q4 = point<deg_C>(20.5);
|
||||
```
|
||||
|
||||
- specify a unit and use its zeroth point origin implicitly:
|
||||
@ -480,7 +480,7 @@ choose from here. Depending on our needs or tastes, we can:
|
||||
quantity_point<si::degree_Celsius> q5 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
|
||||
quantity_point<si::degree_Celsius> q6{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
|
||||
quantity_point<si::degree_Celsius> q7{delta<deg_C>(20.5)};
|
||||
quantity_point<si::degree_Celsius> q8 = absolute<deg_C>(20.5);
|
||||
quantity_point<si::degree_Celsius> q8 = point<deg_C>(20.5);
|
||||
```
|
||||
|
||||
- benefit from CTAD:
|
||||
@ -489,7 +489,7 @@ choose from here. Depending on our needs or tastes, we can:
|
||||
quantity_point q9 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
|
||||
quantity_point q10{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
|
||||
quantity_point q11{delta<deg_C>(20.5)};
|
||||
quantity_point q12 = absolute<deg_C>(20.5);
|
||||
quantity_point q12 = point<deg_C>(20.5);
|
||||
```
|
||||
|
||||
In all of the above cases, we end up with the `quantity_point` of the same type and value.
|
||||
@ -500,7 +500,7 @@ the following way:
|
||||
{style="width:80%;display: block;margin: 0 auto;"}
|
||||
|
||||
```cpp
|
||||
constexpr struct room_reference_temp final : relative_point_origin<absolute<deg_C>(21)> {} room_reference_temp;
|
||||
constexpr struct room_reference_temp final : relative_point_origin<point<deg_C>(21)> {} room_reference_temp;
|
||||
using room_temp = quantity_point<isq::Celsius_temperature[deg_C], room_reference_temp>;
|
||||
|
||||
constexpr auto step_delta = delta<isq::Celsius_temperature<deg_C>>(0.5);
|
||||
|
@ -59,7 +59,7 @@ inline constexpr voltage_hw_t voltage_hw_zero = voltage_hw_range / 2;
|
||||
|
||||
// clang-format off
|
||||
inline constexpr struct hw_voltage_origin final :
|
||||
relative_point_origin<absolute<si::volt>(min_voltage)> {} hw_voltage_origin;
|
||||
relative_point_origin<point<si::volt>(min_voltage)> {} hw_voltage_origin;
|
||||
|
||||
inline constexpr struct hw_voltage_unit final :
|
||||
named_unit<"hwV", mag_ratio<voltage_range, voltage_hw_range> * si::volt, hw_voltage_origin> {} hw_voltage_unit;
|
||||
@ -74,7 +74,7 @@ std::optional<hw_voltage_quantity_point> read_hw_voltage()
|
||||
{
|
||||
voltage_hw_t local_copy = hw_voltage_value;
|
||||
if (local_copy == voltage_hw_error) return std::nullopt;
|
||||
return absolute<hw_voltage_unit>(local_copy);
|
||||
return point<hw_voltage_unit>(local_copy);
|
||||
}
|
||||
|
||||
void print(QuantityPoint auto qp)
|
||||
|
@ -47,7 +47,7 @@ struct delta_ {
|
||||
};
|
||||
|
||||
template<Reference R>
|
||||
struct absolute_ {
|
||||
struct point_ {
|
||||
template<typename FwdRep, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
|
||||
[[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), Rep>
|
||||
operator()(FwdRep&& lhs) const
|
||||
@ -62,7 +62,10 @@ template<Reference auto R>
|
||||
constexpr delta_<MP_UNITS_REMOVE_CONST(decltype(R))> delta{};
|
||||
|
||||
template<Reference auto R>
|
||||
constexpr absolute_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};
|
||||
constexpr point_<MP_UNITS_REMOVE_CONST(decltype(R))> point{};
|
||||
|
||||
template<Reference auto R>
|
||||
[[deprecated("Use `point` instead")]] constexpr point_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};
|
||||
|
||||
MP_UNITS_EXPORT_END
|
||||
|
||||
|
@ -207,7 +207,7 @@ template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})>
|
||||
template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
|
||||
requires detail::OffsetUnit<decltype(get_unit(R{}))>
|
||||
[[deprecated(
|
||||
"References using offset units (e.g., temperatures) should be constructed with the `delta` or `absolute` "
|
||||
"References using offset units (e.g., temperatures) should be constructed with the `delta` or `point` "
|
||||
"helpers")]] constexpr auto
|
||||
operator*(FwdRep&& lhs, R r)
|
||||
{
|
||||
@ -217,7 +217,7 @@ operator*(FwdRep&& lhs, R r)
|
||||
template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
|
||||
requires detail::OffsetUnit<decltype(get_unit(R{}))>
|
||||
[[deprecated(
|
||||
"References using offset units (e.g., temperatures) should be constructed with the `delta` or `absolute` "
|
||||
"References using offset units (e.g., temperatures) should be constructed with the `delta` or `point` "
|
||||
"helpers")]] constexpr auto
|
||||
operator/(FwdRep&& lhs, R)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ inline constexpr struct weber final : named_unit<"Wb", volt * second> {} weber;
|
||||
inline constexpr struct tesla final : named_unit<"T", weber / square(metre)> {} tesla;
|
||||
inline constexpr struct henry final : named_unit<"H", weber / ampere> {} henry;
|
||||
|
||||
inline constexpr struct ice_point final : relative_point_origin<absolute<milli<kelvin>>(273'150)> {} ice_point;
|
||||
inline constexpr struct ice_point final : relative_point_origin<::mp_units::point<milli<kelvin>>(273'150)> {} ice_point;
|
||||
inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
|
||||
|
@ -127,7 +127,7 @@ inline constexpr struct inch_of_mercury final : named_unit<"inHg", mag_ratio<3'3
|
||||
#endif
|
||||
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Temperature
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<absolute<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<::mp_units::point<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct degree_Fahrenheit final : named_unit<symbol_text{u8"℉", "`F"}, mag_ratio<5, 9> * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit;
|
||||
|
||||
// clang-format on
|
||||
|
@ -808,8 +808,8 @@ static_assert(quantity_point{42 * m}.quantity_from_zero() == 42 * m);
|
||||
static_assert(quantity_point{isq::height(42 * m)}.quantity_from_zero() == 42 * m);
|
||||
static_assert(quantity_point{delta<deg_C>(20)}.quantity_from_zero() == delta<deg_C>(20));
|
||||
static_assert(quantity_point{delta<deg_C>(20.)}.in(deg_F).quantity_from_zero() == delta<deg_F>(68));
|
||||
static_assert(absolute<deg_C>(20).quantity_from_zero() == delta<deg_C>(20));
|
||||
static_assert(absolute<deg_C>(20.).in(deg_F).quantity_from_zero() == delta<deg_F>(68));
|
||||
static_assert(point<deg_C>(20).quantity_from_zero() == delta<deg_C>(20));
|
||||
static_assert(point<deg_C>(20.).in(deg_F).quantity_from_zero() == delta<deg_F>(68));
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from_zero() == 42 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from_zero() == 84 * m);
|
||||
|
Reference in New Issue
Block a user