You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been attempting to convert a codebase using version 2 to the 3.x branch and here is some feedback and questions.
I embarked on this upgrade because I grew tired of the inconsistent to_string vs stream behavior for units like volt_t.
My initial, naive, expectation was a drop-in replacement with no change needed in the rest of the code base.
Here is what happened in the hope that's useful for people going through an update. I am planning to send a few PRs as follow-up.
Most of the issues stemmed from using a float underlying type - all of the unit testing is done for double.
v2 Types are templates in v3
I used to do:
#define UNIT_LIB_DEFAULT_TYPE float
using meter_t = units::length::meter_t;
In 3.x I do: using meter_t = units::length::meter_t<float>;
Dealing with literal operators and underlying type
In 3..x it a bit less nicely packaged when it comes to literal operators since I am dealing with floats.
I have to redefine them outside of core.h with a user-land macro since I do not want double:
It's not too bad though, I just had to reintroduce UNIT_HAS_LITERAL_SUPPORT in 3.x.
units::math
It's easy enough to figure out that the math functions are directly available in the units namespace and that units::math is gone.
In a more subtle way, I started to get compilation errors with units::sqrt of the no-template-overload-found variety.
I tracked it down to a 0.5 literal that was causing a mixture of double and floats in the call to sqrtNewtonRaphson. Once found, it was straightforward to replace that with T{0.5}.
Ternary operator and arithmetic operators+,- return type
I hit an issue where the ternary operator no longer compiles:
After sifting through the template compilation errors, it's down to: std::common_type_t<degree_t, degree_t> differing from degree_t, as it's using a dummy 1 conversion factor.
That can be solved through another std::common_type_t specialization.
The text was updated successfully, but these errors were encountered:
Wait, it seems I was missing some significant updates to v3.x, for example the _t suffix is gone entirely now. I need to review and update what I said above.
Ok after a bit of renaming I managed to make almost everything work on 3.x - I updated all the PRs above, they should be good for review/feedback.
The one thing that's not working for me in 3.x as it used to on 2.3 is to_string for on-the-fly units, e.g. : to_string(1_A * 1_A);
It used to print: 1 A^2
but now I am getting a compilation error.
Not a bit deal for me at the moment, I might look into that at a later stage unless someone has a better understand of what's going on here.
I also opened #318 and #317, they are self-explanatory
Overall things feel much cleaner in 3.x, Thanks. Straightening up the ADL story makes a big difference.
Regarding testing, my use case makes use of float underlying_type which makes me notice how current tests cover double underlying_type. I am not sure how to extend that without a lot of code duplication. Something like templating the test cases on underlying type?
Uh oh!
There was an error while loading. Please reload this page.
I have been attempting to convert a codebase using version 2 to the 3.x branch and here is some feedback and questions.
I embarked on this upgrade because I grew tired of the inconsistent
to_string
vsstream
behavior for units like volt_t.My initial, naive, expectation was a drop-in replacement with no change needed in the rest of the code base.
Here is what happened in the hope that's useful for people going through an update. I am planning to send a few PRs as follow-up.
Most of the issues stemmed from using a
float
underlying type - all of the unit testing is done fordouble
.I used to do:
In 3.x I do:
using meter_t = units::length::meter_t<float>;
In 3..x it a bit less nicely packaged when it comes to literal operators since I am dealing with floats.
I have to redefine them outside of core.h with a user-land macro since I do not want
double
:It's not too bad though, I just had to reintroduce
UNIT_HAS_LITERAL_SUPPORT
in 3.x.I tracked it down to a 0.5 literal that was causing a mixture of double and floats in the call to
sqrtNewtonRaphson
. Once found, it was straightforward to replace that with T{0.5}.I hit an issue where the ternary operator no longer compiles:
After sifting through the template compilation errors, it's down to:
std::common_type_t<degree_t, degree_t>
differing fromdegree_t
, as it's using a dummy 1 conversion factor.That can be solved through another
std::common_type_t
specialization.The text was updated successfully, but these errors were encountered: