-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add utilities to forward declare compound units #342
Conversation
The mechanism may be a little bit complicated, but I think it's manageable. It's also necessary in order to get forward declaration files working in Aurora's monorepo, which was what I used to design the feature. The fact that we're now able to do so gives me confidence that Au's forward declarations now have everything they need to be useful and usable in the real world. I also added a how-to doc explaining how to use the forward declaration feature generally. Fixes #232.
practices](./new-units.md#alias-vs-strong) for new units suggests using a simple _alias_ in this | ||
case, rather than a strong type (for example, `UnitQuotientT<Meters, Seconds>`). However, this | ||
cannot be computed without the full machinery of the library, which can cost tens of milliseconds. | ||
This may not sound like much, but it's far too slow for a forward declaration file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we quantify what is the too slow and what is the target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (0bb43ee).
using KilometersPerHourFwd = au::ForwardDeclareUnitProduct<au::Kilo<au::Meters>, InverseHours>; | ||
using KilometersPerHour = typename KilometersPerHourFwd::unit_type; | ||
|
||
std::string print_to_string(const au::QuantityD<KilometersPerHour>& speed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I was hoping that the fwd types would be named the same as the underlying types. But I guess that wouldn't have the checks that we care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this was the cleanest way I could think of to make it easy to check the answers robustly.
The mechanism may be a little bit complicated, but I think it's
manageable. It's also necessary in order to get forward declaration
files working in Aurora's monorepo, which was what I used to design the
feature. The fact that we're now able to do so gives me confidence that
Au's forward declarations now have everything they need to be useful and
usable in the real world.
I also added a how-to doc explaining how to use the forward declaration
feature generally.
Fixes #232.