-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Quantity non-type template parameters (#318)
Technically, we can't get non-type template parameters of custom class type until C++20. But for a `Quantity<U, R>` whose rep `R` is integral, we can get the next best thing! This PR introduces a public member typedef, `Quantity<U, R>::NTTP`, which _can_ be used as a template parameter, because it's an enumeration. We support _bidirectional, implicit_ conversion between `Quantity<U, R>` and `Quantity<U, R>::NTTP`, as long as there's an exact match for `U` and `R`. In all other cases, users must use the usual `Quantity` conversion operators to get it into the right type. They can also explicitly request conversion from the NTTP to the `Quantity` by passing the former to `from_nttp(...)`. It's a niche use case, but it's finally possible to use a `Quantity` as a template parameter in a unit-safe way! There just was no other comparable solution before this. Compile time measurements are ongoing, but so far they suggest a small but nonzero penalty. It appears that it varies from file to file, but is generally less than 50 ms. I think that's an OK price to pay for this feature. Fixes #316.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters