mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

refactor(core): replace `convert_*` wrappers with a member query

Open JohelEGP opened this issue 1 year ago • 5 comments

Title: refactor(core): replace convert_* wrappers with a member query.

Description:

Replace https://github.com/mpusz/mp-units/blob/89bafed9619a4a8320046e2be621172a6e88b586/src/core/include/mp-units/framework/customization_points.h#L144-L162 with these members in the quantity-like-traits templates:

  static constexpr bool to_numerical_value_is_explicit = false;
  static constexpr bool from_numerical_value_is_explicit = false;

That removes the need to wrap and unwrap the numbers, and simplifies the expressions in the explicit specifiers.

This will also require updating

  • their use in the quantity templates,
  • the std::chrono support,
  • their own tests,
  • any use in the examples, and
  • the user guide documentation.

JohelEGP avatar Oct 13 '24 01:10 JohelEGP

Naming is hard 😉:

  1. This does not control the convertibility to/from a numerical value, but to /from quantity/quantity_point. I do not have a good idea of how to rename this, though.
  2. Should we mention "explicit" or "implicit" in the identifier?
  3. Maybe we should be consistent with is_transparent and provide a type instead of the bool value instead?
  4. Should both flags be true by default and not have to be provided in such case? Or should we always specify them and mandate this in a concept?

mpusz avatar Oct 13 '24 19:10 mpusz

Naming is hard 😉:

  1. This does not control the convertibility to/from a numerical value, but to /from quantity/quantity_point. I do not have a good idea of how to rename this, though.

I'm still thinking.

  1. Should we mention "explicit" or "implicit" in the identifier?

Explicit to avoid negations in the explicit specifiers.

  1. Maybe we should be consistent with is_transparent and provide a type instead of the bool value instead?

That just makes the explicit specifiers harder to specify.

  1. Should both flags be true by default and not have to be provided in such case? Or should we always specify them and mandate this in a concept?

I prefer explicitly requiring them.

JohelEGP avatar Oct 13 '24 19:10 JohelEGP

Maybe:

static constexpr bool to_quantity_is_explicit = false;
static constexpr bool from_quantity_is_explicit = false;

and

static constexpr bool to_quantity_point_is_explicit = false;
static constexpr bool from_quantity_point_is_explicit = false;

?

mpusz avatar Oct 13 '24 19:10 mpusz

The problem I have with that is that the "like" parameter is also a quantity (point). So the direction is still confusing, "from our quantity, or their quantity?".

JohelEGP avatar Oct 13 '24 19:10 JohelEGP

You can also say that those also have some numerical value 😉 I could argue that that others are not "quantities" but duration or MyMetre. Unless it is about the cooperation with Au which uses proper names 😉

So maybe:

static constexpr bool explicit_import = false;
static constexpr bool explicit_export = false;

?

Naming is hard 😉

mpusz avatar Oct 13 '24 19:10 mpusz

It seems like this was fixed by commit 975025f88a3f58ffc39ca4a4100f40d6a8ca5eff.

JohelEGP avatar Oct 29 '24 16:10 JohelEGP