-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider providing constant
instead of named_unit
for constants
#677
Comments
From my point of view, the right answer is straight forward: "we don't want to allow CTAD". The mp-units-ification of the corresponding Au interfaces would probably look something like |
Well, I did not plan to add any fancy interface (like I thought that maybe being able to pass Then I realized that we encourage people to use generic programming with concepts (e.g., |
Yeah, it's on me to write a doc to explain the concept of "shapeshifter types". These are monovalue types that can "shapeshift" to become any type from some family of types. The "superpower" of a shapeshifter type is that it enables effortless comparisons, additions, subtractions, assignments, etc. with any one type from that family of types. You can simply "compare to Their weakness --- their "kryptonite", if you will --- is that you can only use them in a context where it's clear which type they need to become, which is not true for generic interfaces. So, bringing a shapeshifter type to a generic interface is simply an incorrect usage. Once we have good explanations of shapeshifter types as a concept* that we can link to, then the community can learn that this simply isn't how to use them. And then we can get the benefits of the use cases where they do apply. I am hoping to give a talk on Monovalue Types in CppCon 2025, and "shapeshifter types" will be a key component if I do. Anyway: I really do think CTAD is the wrong direction to go here, because there's no way to get it without privileging some choice of rep above all others, and I want to avoid doing that. *"As a concept": concept in the generic sense, not the C++20 sense, naturally. |
Why not give them the reference treatment, so that |
They actually work as a reference now, and we can type |
Such constants could have superpowers. They could implicitly convert to a quantity and provide additional compile-time overflow protection as discussed in #669_
One possible problem is to decide which representation type should be used in case we want to allow CTAD (e.g.,
quantity{si::standard_gravity}
). Forcingstd::arithmetic
types might be a no-go for some projects that use safe numeric wrappers. This is actually where the current unit-based approach shines. The constant is orthogonal to the representation type in a quantity.The text was updated successfully, but these errors were encountered: