C++ Logo

std-proposals

Advanced search

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

From: Mateusz Pusz <mateusz.pusz_at_[hidden]>
Date: Wed, 19 Jun 2024 11:17:29 +0200
That is a very good point. I'm not sure what to do about it. Some people
suggested that we need to do some bikeshedding here anyway. Maybe we can
find better names for quantity and quantity_point that would better express
what we are dealing with. `quantity` could be renamed to `quantity_delta`
or `quantity_difference` to be more explicit about what it means and does.
However, I am not sure if that is a good idea...

śr., 19 cze 2024 o 09:52 Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> napisał(a):

> Hi Mateusz,
>
>
>
> that is a good overview of the discussion.
>
>
>
> The initial example by Tiago was:
>
>
>
> ```
>
> quantity Volume = 1.0 * m*m*m;
>
> quantity Temperature = (28.0 * deg_C).in(K);
>
> quantity n_ = 0.04401 * kg / mol;
>
> quantity R_boltzman = 8.314 * N * m / (K * mol);
>
> quantity mass = 40.0 * kg;
>
> quantity Pressure = R_boltzman * Temperature * mass / n_ / Volume;
>
> std::cout << Pressure << std::endl;
>
> ```
>
>
>
>
>
> Removing the multiplicative syntax would only help insofar as:
>
> `quantity` now has to be used explicitly; with multiplication `auto` would
> have been possible instead.
>
>
>
> auto Temperature = (28.0 * deg_C).in(K);
>
>
>
>
>
>
>
>
>
> Only quantity and never quantity_point is used for the other units. So
> users have to know that quantity_point exists and that it has to be used
> specifically for temperature, even it is possibly not used for any of the
> other units (see this example). That still keeps the temperature
> error-prone:
>
>
>
> auto Temperature = (quantity{28.0, deg_C}).in(K);
>
>
>
> is wrong. But looks correct for users not knowing quantity_point.
>
>
>
>
>
>
>
>
>
>
>
> With the proposed change, we would always have to write:
>
> auto t1 = quantity{10, deg_C};
> auto t2 = quantity_point{quantity{10, deg_C}}; // current design
> auto t3 = quantity_point{10, deg_C}; // possible extension
> with a new constructor overload
>
> With this syntax, I think it gets really clear what we are dealing with in
> each case.
>
> How do we feel about such an interface?
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-06-19 09:17:44