C++ Logo

std-proposals

Advanced search

Re: [std-proposals] On the standardization of mp-units P3045R1

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 27 Jun 2024 20:10:18 +0300
On Wed, 26 Jun 2024 at 23:17, Mateusz Pusz via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> During the discussion in the SG6 it was raised that that `30 * absolute<deg_C>` feels wrong, and I tend to agree with that. This was the only usage of `absolute` so, if multiply syntax should not use it, the `absolute` can be removed. After that, `30 * delta<deg_C>` looks like a hack and not a feature.
>
> I am looking for some other solutions that would help here. Maybe we should:
> - disallow the multiply syntax for offset units (K, deg_C, deg_F),
> - change `delta` to be a functor and call it as `delta<deg_C>(20)` which produces a `quantity`
> - re-add `absolute` to create a `quantity_point` with the same syntax (e.g., `absolute<deg_C>`)
>
> With the above, we would end up with the following helpers:
>
> ```cpp
> quantity q1 = 40 * m;
> quantity q2 = delta<m>(40);
> quantity_point q3 = absolute<m>(40);
> quantity q4 = 40 * deg_C; // Compile-time error
> quantity q5 = delta<deg_C>(40);
> quantity_point q6 = absolute<deg_C>(40);
> quantity q7 = 40 * isq::thermodynamic_temperature[deg_C]; // Compile-time error
> quantity q8 = delta<isq::thermodynamic_temperature[deg_C]>(40);
> quantity_point q9 = absolute<isq::thermodynamic_temperature[deg_C]>(40);
> ```
>
> With the proposed change, I hope that is more evident what the following code does:
>
> ```cpp
> quantity q = delta<K>(300);
> quantity_point qp = absolute<K>(300);

These look very clear to me.

> static_cast(q.in(deg_C) != qp.in(deg_C).quantity_from_zero());

This one less so. Also.. huh? static_cast to what?

Why can't we just have a to_absolute<T>(U) ?

Received on 2024-06-27 17:10:32