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

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

Open
JohelEGP opened this issue Oct 13, 2024 · 5 comments
Open

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

JohelEGP opened this issue Oct 13, 2024 · 5 comments

Comments

@JohelEGP
Copy link
Collaborator

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

Description:

Replace

template<typename T>
struct convert_explicitly {
using value_type = T;
T value;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) convert_explicitly(T v) noexcept(std::is_nothrow_constructible_v<T>) : value(std::move(v))
{
}
};
template<typename T>
struct convert_implicitly {
using value_type = T;
T value;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
constexpr explicit(false) convert_implicitly(T v) noexcept(std::is_nothrow_constructible_v<T>) : value(std::move(v))
{
}
};

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.
@mpusz
Copy link
Owner

mpusz commented Oct 13, 2024

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?

@JohelEGP
Copy link
Collaborator Author

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.

@mpusz
Copy link
Owner

mpusz commented Oct 13, 2024

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;

?

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Oct 13, 2024

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?".

@mpusz
Copy link
Owner

mpusz commented Oct 13, 2024

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 😉

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

No branches or pull requests

2 participants