C++ Logo

std-proposals

Advanced search

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

From: Mateusz Pusz <mateusz.pusz_at_[hidden]>
Date: Thu, 27 Jun 2024 22:19:46 -0500
Well, you do not have to use any "gadgets" during the construction if you
do not like to. You can always use a 2-parameter constructor that takes a
number and a unit. As Chip mentioned, taking only a unit is considered a
safety issue, which is why it is not allowed in the library.

czw., 27 cze 2024 o 13:53 Tiago Freire via Std-Proposals <
std-proposals_at_[hidden]> napisał(a):

> > In your specific example, this would be less likely because you've
> included the full unit name in your alias. However, not everyone wants to
> do this --- often, people want to give it a more generic alias, like
> `temperature`. Preventing this constructor from a single value (even when
> `explicit`), and making sure that every option forces the user to name the
> unit explicitly at the callsite, preserves unit safety, and reduces
> cognitive load.
>
>
>
> I think you focused too much on the alias part, while the important part
> is a fully named type. In many codes bases the rule to explicit type out
> your types are a thing.
>
> If I can fully type out the type that I want, why shouldn’t I be able to
> use it?
>
> Why exactly do I need a separate gadget to create that type?
>
> Talking about a mental effort, it is not enough to know the type that you
> want, you also need to lookup the right gadget (whose name has nothing to
> do with the type you are trying to construct) in order to construct your
> type,… what? Why?
>
>
>
> This doesn’t have the confusing problem that “30 * deg_C” feels wrong,
> because it is wrong, it’s not a multiplication why do you write it as a
> multiplication?
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-06-28 03:20:00