Replies: 4 comments 5 replies
-
OK, so I can write a Quantity auto operator+(Quantity auto lhs, Quantity auto rhs); The first problem is what should be the result of But now, other libraries do the same (i.e. pqs defined it already). I hope you implemented it exactly token-wise the same as I did in |
Beta Was this translation helpful? Give feedback.
-
The discussion about problems with the conversion factor being a rational number to a base10 exponent #195 throws up another issue. The conversion factor should be a concept. The Concept should specify what is required, presumably some compile time evaluable function to convert a value in unit A to a value in unit B, but shouldn't specify any implementation details as to how it should be done. Requiring the conversion factor to be a mpusz ratio type is over specifying it. #187 (comment). which limits extensibility FWIW my own library makes this error currently as well. https://github.com/kwikius/pqs/wiki/type_template-conversion_factor |
Beta Was this translation helpful? Give feedback.
-
As I stated already here I considered such an option but it has also many issues. Ratio arithmetic is hard. If you do not believe me see here:
|
Beta Was this translation helpful? Give feedback.
-
As said, I think it is a good idea to provide such a concept but was of a low priority so far. I still think it is a low priority because I would love to find a solution that would work for angles with one Anyway, it might be a bit bigger and more tricky than mentioned above:
template<std::intmax_t Num, std::intmax_t Den = 1>
requires detail::non_zero<Den>
[[nodiscard]] constexpr ratio pow(const ratio& r)
|
Beta Was this translation helpful? Give feedback.
-
mp_units uses a singe template type quantity. but there is another way. Make quantity a concept and provide operations that work on any valid model of quantity.
The advantage is that existing types that model the concepts can be reused with out abi modifications, while working seamlessly with the library.
An example of how existing types can be reused in this way is std::chrono::duration
With the concept based approach std::chrono::duration is a valid quantity
Sample pqs syntax involving chronos::duration and pqs quantiies
static_assert(1s + 1q_s == 2q_s);
In mpunits The chrono::duration must first be converted ,using the already overused explicit conversion syntax, to the mpunits quantity type before it will work with the library
The same expressed in mpusz syntax
static_assert(quantity{1s} + 1_q_s == 2_q_s);
A basic set of concepts for the concepts based approach is documented here
The C++ implementation is here
Beta Was this translation helpful? Give feedback.
All reactions