-
Notifications
You must be signed in to change notification settings - Fork 87
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 support for zero
#487
Comments
mp-units/example/glide_computer_lib/glide_computer_lib.cpp Lines 48 to 49 in 99bec8e
|
Should static_assert((1 * m *= zero) == zero);
static_assert((1 * m /= zero) == zero);
static_assert((1 * m) * zero == zero);
static_assert(zero * (1 * m) == zero);
static_assert(zero / (1 * m) == zero); I think that the above is controversial because it breaks the following logic:
If we would like to extend that logic to |
It seems that there are also some cases where mp-units/example/capacitor_time_curve.cpp Line 42 in 99bec8e
mp-units/example/unmanned_aerial_vehicle.cpp Line 134 in 99bec8e
|
In fact, after closely reviewing all our examples, the only place where template<typename T>
struct MP_UNITS_STD_FMT::formatter<geographic::latitude<T>> : formatter<T> {
template<typename FormatContext>
auto format(geographic::latitude<T> lat, FormatContext& ctx)
{
- MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", lat > geographic::latitude<T>::zero() ? 'N' : 'S');
- return formatter<T>::format(lat > geographic::latitude<T>::zero() ? lat.numerical_value() : -lat.numerical_value(), ctx);
+ MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", lat > mp_units::zero ? 'N' : 'S');
+ return formatter<T>::format(lat > mp_units::zero ? lat.numerical_value() : -lat.numerical_value(), ctx);
}
};
template<typename T>
struct MP_UNITS_STD_FMT::formatter<geographic::longitude<T>> : formatter<T> {
template<typename FormatContext>
auto format(geographic::longitude<T> lon, FormatContext& ctx)
{
- MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", lon > geographic::longitude<T>::zero() ? 'E' : 'W');
- return formatter<T>::format(lon > geographic::longitude<T>::zero() ? lon.numerical_value() : -lon.numerical_value(), ctx);
+ MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", lon > mp_units::zero ? 'E' : 'W');
+ return formatter<T>::format(lon > mp_units::zero ? lon.numerical_value() : -lon.numerical_value(), ctx);
}
}; I am not sure if this is enough to justify complicating design with new features and a bunch of overloads 🥴 |
Maybe just our short examples are not representing the production code base well enough? In bigger projects people will have quantity types stored in some structures and not deduced by On the other hand, it is probably much better to benefit from the zero-initialization... |
As I am puzzled about what to do with this feature, I pushed it to PR #488 so you can assess the benefits and changes required to implement it. Please let me know what you think. |
I hadn't thought of multiplicative use cases before! The way to think of
Yeah, Also --- and this may be vague and hard to express --- but it feels like As for the second example, it wasn't clear to me why
I grepped our codebase for |
If we replace |
Thanks, that convinces me to merge this feature :-) |
Oh, good point --- this is just my lack of experience with mp-units quantity point showing. Makes sense! |
I have just learned the following: https://godbolt.org/z/689Wa188h. We can treat literal |
That's the behavior of the built-in |
Isn't it portably implemented for comparison categories? |
I suppose you could detect the C++ standard library being used, and do it their way. Maybe the fragile implementation will always work for our use case. |
zero
is really useful, as described here: https://aurora-opensource.github.io/au/main/discussion/concepts/zero.The text was updated successfully, but these errors were encountered: