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

feat: quantity_kind and quantity_point_kind #204

Merged
merged 1 commit into from
Feb 15, 2021

Conversation

JohelEGP
Copy link
Collaborator

Resolves #173.
Partially addresses #172.
Resolves 3239186#r45824165.

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Jan 12, 2021

I still need to deal with MSVC and UNITS_DOWNCAST_MODE.

You'll notice that I chose to actually instantiate stuff rather than just checking their signature with type traits/concepts/require clauses. That's what led me to find the inconsistencies in (lack of) warnings.

Similarly, I test the validity of individual expressions in the tests' concepts. Remember when quantity didn't model std::equality_comparable due to the lack of a std::common_type specialization, and yet == was used everywhere? I'm basically testing that we don't accidentally provide a nonsensical ==, whereas testing with std::equality_comparable could fail for whatever reason. That's because it checks many things in addition to the expressions.

@mpusz
Copy link
Owner

mpusz commented Jan 13, 2021

Just as a reminder UNITS_DOWNCAST_MODE=OFF still does not work.

{
return formatter<Q>::format(v.magnitude(), ctx);
return formatter<typename QK::quantity_type>::format(v.common(), ctx);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By the way, I got this when using fmt's master branch. The quantity formatter uses a removed fmt::detail:: name.

../../../example/glide_computer.cpp:144:17:   required from ‘void {anonymous}::print(const R&) [with R = std::array<{anonymous}::glider, 4>]’
../../../example/glide_computer.cpp:380:16:   required from here
/home/johel/Documents/C++/Forks/mpusz/units/src/src/include/units/format.h:91:73: error: ‘make’ is not a member of ‘fmt::v7::detail::fill_t<char>’

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, that was using my system-wide fmt, the latest stable release at the time.

Copy link
Owner

Choose a reason for hiding this comment

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

Should be fixed now with f9b15dd

@JohelEGP JohelEGP force-pushed the quantity_kind branch 2 times, most recently from cd9580c to 8402d95 Compare January 19, 2021 22:07
@JohelEGP
Copy link
Collaborator Author

Can you confirm that this supports UNITS_DOWNCAST_MODE well?

@JohelEGP JohelEGP force-pushed the quantity_kind branch 2 times, most recently from f9bba80 to a3d415b Compare January 21, 2021 21:51
@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Feb 4, 2021

I agree with #100 (comment). I'll be removing those. I started using this PR, and instead of quantity_kind(my_kind{}, ...), I find myself using alias templates, like how example/glide_computer.cpp uses type aliases.

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Feb 4, 2021

I have taken a liking to doing something like unit_constants for quantity kinds. I call it variable_definition for now.

inline constexpr variable_definition<width> w{};
template <units::basic_fixed_string> auto operator""_v();
template <> auto operator""_v<"λ">() { return variable_definition<wavelength>{} };

f(w = 42 * m);
g("λ"_v = (42 * m / s) / (42 * Hz));

It is meant to mirror the lhs of math formulas. And to make quantity kind creation less verbose, similar to unit constants.

Would you be opposed to having something like this?

Copy link
Owner

@mpusz mpusz left a comment

Choose a reason for hiding this comment

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

WOW, this is HUGE!!! :-D

Thank you so much!!!

{
return formatter<Q>::format(v.magnitude(), ctx);
return formatter<typename QK::quantity_type>::format(v.common(), ctx);
Copy link
Owner

Choose a reason for hiding this comment

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

Should be fixed now with f9b15dd

@mpusz mpusz merged commit 6bf09aa into mpusz:master Feb 15, 2021
@JohelEGP JohelEGP deleted the quantity_kind branch February 15, 2021 18:32
@mpusz
Copy link
Owner

mpusz commented Feb 15, 2021

Now we need some docs 😉

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Feb 15, 2021

What exactly? The PR did include some, mirroring quantity_point's.

mpusz added a commit that referenced this pull request Feb 15, 2021
@mpusz
Copy link
Owner

mpusz commented Feb 15, 2021

Sorry, my fault. The docs were there but they were not added to TOC.

@JohelEGP
Copy link
Collaborator Author

I thought I had done it:
https://github.com/mpusz/units/pull/204/files#diff-5b31041ef4b51a5ffbdf42e822a8b885f6e3ac8ed6b06b3958417f50a35a8a15R73

I see now that there's some repetition involved.

Perhaps using actions/upload-artifact to upload the generated documentation could help alleviate this in the future. That way, contributors who don't setup conan and everything else can still confirm that everything looks good.

@mpusz
Copy link
Owner

mpusz commented Feb 16, 2021

Agree, we could try to setup actions/upload-artifact for https://github.com/mpusz/units/actions?query=workflow%3ADocumentation when not run from the master branch. However, the artifact will be just *.zip archive. Do you think that contributors will be willing to download, extract, and verify them?

@JohelEGP
Copy link
Collaborator Author

The more documentation in the PR, the more likely that is.

@mpusz
Copy link
Owner

mpusz commented Feb 16, 2021

Isn't it easier to build and fix the docs locally? For example, what is the reason you are not doing so? Please note that some time ago I added UNITS_BUILD_DOCS CMake cache variable. With this, you can install Conan dependencies with build_docs=true and then disable the docs in CMake and enable only when needed.

@JohelEGP
Copy link
Collaborator Author

I think it may have been the struggle of using a new tool, namely Conan, in the past. I'll try it again, though.

@mpusz
Copy link
Owner

mpusz commented Feb 16, 2021

Thanks, just follow https://mpusz.github.io/units/usage.html#contributing-or-just-building-all-the-tests-examples-and-documentation. And please let me know in case of issues.

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.

Support for quantity_kind
2 participants