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 compatibility utility for nholthaus units #112

Merged
merged 3 commits into from
Feb 22, 2023
Merged

Conversation

chiphogg
Copy link
Contributor

This creates a file, "compatibility/nholthaus_units.hh", which makes
it easy to set up a correspondence between each Au Quantity type, and
the corresponding nholthaus units type. This "correspondence" includes
bidirectional implicit conversions: so, you can pass
::au::QuantityD<Meters> to an API expecting
::units::length::meter_t, and vice versa.

This correspondence is purely opt-in. The file also needs to be
included after both of the other two libraries are included. Since
this is fragile in general, we give instructions and an example for how
to make it not fragile, in nholthaus_units_example_usage.hh.

We include a variety of unit tests to show that the quantities are
indeed equivalent between the libraries. (Actually, this isn't quite
always the case. These tests uncovered a bug in the nholthaus library,
nholthaus/units#289.)

We reserve the documentation of the corresponding-quantity feature in
general, as well as its application to the nholthaus library, for a
future PR.

Test plan

  • Add new unit tests for this file.
  • Add example file that shows how to use it.
  • Test that the file can replace Aurora's existing implementation.

This creates a file, `"compatibility/nholthaus_units.hh"`, which makes
it easy to set up a correspondence between each Au Quantity type, and
the corresponding nholthaus units type.  This "correspondence" includes
bidirectional implicit conversions: so, you can pass
`::au::QuantityD<Meters>` to an API expecting
`::units::length::meter_t`, and vice versa.

This correspondence is purely opt-in.  The file also needs to be
included _after_ both of the other two libraries are included.  Since
this is fragile in general, we give instructions and an example for how
to make it _not_ fragile, in `nholthaus_units_example_usage.hh`.

We include a variety of unit tests to show that the quantities are
indeed equivalent between the libraries.  (Actually, this isn't quite
always the case.  These tests uncovered a bug in the nholthaus library,
nholthaus/units#289.)

We reserve the documentation of the corresponding-quantity feature in
general, as well as its application to the nholthaus library, for a
future PR.
@chiphogg chiphogg requested a review from geoffviola February 20, 2023 22:57
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only did a quick review. The usage header gives some notes on how to #include it and the tests provide sample conversions. Seems useful for migration. Thanks!

@chiphogg chiphogg merged commit 1ec3589 into main Feb 22, 2023
@chiphogg chiphogg deleted the chiphogg/migrate#107 branch February 22, 2023 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants