Question about V2 and migration to it #454
-
Hi there, I'm using this library quite some time now, but only with a very limited number of units. I've wrapped it into some typedefs and written my own (fmt) formatter, because yours couldn't what I wanted, at least at that time. Since I am about to add some new units to my wrapper I checked for updates and found V2. This seems to be quite different, is there any documentation on how to migrate from V1 to V2? My use cases (up until now) are like: Units::Byte<std::int64_t> bytes = 1 * KiB;
Units::Byte<std::int64_t> secondByte{2 * B};
Units::KibiByte<std::int64_t> kibiBytes{1 * KiB};
auto result = bytes + Units::Byte<std::int64_t>{kibiBytes}; So I'd like to have a (prefixed) quantity as template on the underlying type, and the V1 references, I don't care how they are called in V2 and how this is implemented. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 24 replies
-
There's some general documentation here: https://github.com/mpusz/units/pull/397/files. |
Beta Was this translation helpful? Give feedback.
-
@HazardyKnusperkeks Thanks for the interest in the library 😉 The V2, unfortunately, is still WIP (Work In Progress) on a branch which even does not properly compile now. I hope to finish it for gcc-12 in the next month or so and then make other compilers work with it as well. All of this takes a lot of time 😢 V2 will be a big breaking change, so definitely some changes to the codebase will be needed. The changes are in class templates, namespace names, header file names, and files layout. You can find some look and feel and rationale for V2 here: https://github.com/train-it-eu/conf-slides/blob/master/2023.04%20-%20ACCU%202023/mp-units%20-%20Lessons%20learned%20and%20a%20new%20library%20design.pdf. In the V2, your example code can look like this: quantity<byte, std::int64_t> bytes = 1 * KiB;
quantity<byte, std::int64_t> secondByte = 2 * B;
quantity<kibi<byte>, std::int64_t> kibiBytes = 1 * KiB;
auto result = bytes + kibiBytes[byte]; or auto bytes = (std::int64_t{1} * KiB)[byte];
auto secondByte = std::int64_t{2} * B;
auto kibiBytes = std::int64_t{1} * KiB;
auto result = bytes + kibiBytes; or quantity<storage_capacity[byte], std::int64_t> bytes = (std::int64_t{1} * KiB)[byte];
quantity<storage_capacity[byte], std::int64_t> secondByte = 2 * B;
quantity<storage_capacity[kibi<byte>], std::int64_t> kibiBytes = 1 * KiB;
auto result = bytes + kibiBytes[byte]; It is up to you to choose the one you prefer. Of course, you can provide user-specific helpers (i.e. alias templates) to have any desired syntax.
Could you please share what is your desired formatting and how it differs from the one provided in the library. Please note, that the V2 already provides nice extensions in this domain as well. You can find samples in the below links: |
Beta Was this translation helpful? Give feedback.
@HazardyKnusperkeks Thanks for the interest in the library 😉
The V2, unfortunately, is still WIP (Work In Progress) on a branch which even does not properly compile now. I hope to finish it for gcc-12 in the next month or so and then make other compilers work with it as well. All of this takes a lot of time 😢
V2 will be a big breaking change, so definitely some changes to the codebase will be needed. The changes are in class templates, namespace names, header file names, and files layout. You can find some look and feel and rationale for V2 here: https://github.com/train-it-eu/conf-slides/blob/master/2023.04%20-%20ACCU%202023/mp-units%20-%20Lessons%20learned%20and%20a%20new%20library%20de…