Skip to content
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

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

chiphogg
Copy link
Contributor

@chiphogg chiphogg commented Dec 6, 2024

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.

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.
@chiphogg chiphogg added release notes: ✨ lib (enhancement) PR enhancing the library code release notes: 📝 documentation PR affecting library documentation labels Dec 6, 2024
@chiphogg chiphogg requested a review from geoffviola December 6, 2024 00:37
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.
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@chiphogg chiphogg merged commit 4c66b86 into main Dec 6, 2024
13 checks passed
@chiphogg chiphogg deleted the chiphogg/fwd-unit-product#232 branch December 6, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: 📝 documentation PR affecting library documentation release notes: ✨ lib (enhancement) PR enhancing the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide forward declarations
2 participants