mpusz / wg21-papers

ISO C++ Committee papers by Mateusz Pusz
https://mpusz.github.io/wg21-papers
4 stars 7 forks source link

Add motivation and example re. extensibility #34

Closed rothmichaels closed 11 months ago

rothmichaels commented 11 months ago

I thought it might be useful to have a motivation and example about the need for library users to be able to define domain specific quantities and units with all the functionality provided by library quantitites and units.

I wrote this on the plane after CppCon when I was a bit tired, so maybe it needs an editing pass for clarity.

mpusz commented 11 months ago

@rothmichaels I think that I raced with @JohelEGP review while merging this PR. Could you please still consider adding the proposed changes?

rothmichaels commented 11 months ago

@mpusz sure thing. I'll make some updates tonight when I get back to my hotel.

At least the storage tank example comes from https://github.com/mpusz/mp-units. If that's the case for all others, I guess @mpusz would ask you for a PR there to ensure the paper's version stays up-to-date.

Do you want me to open a PR for mp-units with this new example?

mpusz commented 11 months ago

I think it is a great example to have in mp-units as well :-) Before submitting the PR, please check out my changes to your sample in the paper and Compiler Explorer. BTW, I am still thinking if you should use a strong dimension or dimensionless quantities for your case. I checked that the IEC 80000 uses the latter for bits:

https://github.com/mpusz/mp-units/blob/b7e2033d33fa42843de38cfc6d0f2a4875caff4b/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h#L48

This is needed for storage capacity to be able to be expressed both in bits and in a unit one:

https://github.com/mpusz/mp-units/blob/b7e2033d33fa42843de38cfc6d0f2a4875caff4b/test/unit_test/static/iec80000_test.cpp#L54

In case you would like to prevent the usage of one, then a strong dimension is recommended.