-
Notifications
You must be signed in to change notification settings - Fork 87
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
Refactor units::exponent
#166
Comments
A simple case might be just to find a better name. |
Another approach is to change the dimension specification to contain exponent right away. It yields shorter types in error messages. BEFORE:
AFTER:
However, to make it happen we will need to change every base dimension to: template<Unit U, std::intmax_t Num, std::intmax_t Den = 1>
struct dim_length : base_dimension<"L", U, Num, Den> {}; namespace si {
template<std::intmax_t Num, std::intmax_t Den = 1>
struct dim_length : physical::dim_length<metre, Num, Den> {};
} Every derived dimension to: template<typename Child, Unit U, DimensionOf<dim_length> L, DimensionOf<dim_time> T, std::intmax_t Num, std::intmax_t Den = 1>
struct dim_speed : derived_dimension<Child, U, Num, Den, L<1>, T<-1>> {}; namespace si {
template<std::intmax_t Num, std::intmax_t Den = 1>
struct dim_speed : physical::dim_speed<dim_speed, metre_per_second, Num, Den, dim_length, dim_time> {};
} Somehow make the template<Unit U, ScalableNumber Rep = double>
using length = quantity<dim_length, U, Rep>; Or alternatively template<Unit U, ScalableNumber Rep = double>
using length = quantity<dim_length<>, U, Rep>; rather than: template<Unit U, ScalableNumber Rep = double>
using length = quantity<dim_length<1>, U, Rep>; |
As said before, I would recommend thinking about decoupling dimension from dependence on unit as it has currently in mpusz/units, then dimension can be used for different measurement systems In PQS I defined each base_quantity (called in mpusz/units base_dimension I think) as a unique type that conform to base_quantity concept. As part of the interface of a base_quantity I instantiated a global constant of each base_quantity_exponent raised to exponent 1 for reasons explained next I provide operators *,/ etc to work on models of dimension so they can be multiplied , divide, raised to power etc, which makes for very convenient user interface for constructing derived dimensions, e.g dimension abstract_force here: There are some more subtleties as to whether to make a dimension a derived class or use a typedef (relating to units output) which I wont go into here. Anyway it makes for a very satisfying user interface for dimension EDIT: It may als be possible to convert the interface of many entities to use NTTP dimensions rather than types so that the decltype( expr) syntax would not be needed much or at all. |
Thanks, I will look into it soon (right now I have to prepare for a 2-day CppCon workshop that starts on Monday, and then I have to catch up with my paid work as I spent the last 2-weeks exclusively on units). |
This is definitely worth looking into. |
We can reuse dimension definitions between systems even now. We just share a class template rather than a specific type. Regarding the decoupling, are you sure that it will be possible to still support all the current use cases (multiple systems support with various units and printing them properly in the text output)? NTTP usage for dimensions will most probably make error logs much worse as there is no way to make downcasting work with values. |
However, I plan to make some major changes to the design soon that may affect this subject too. Mostly they are to support #48. |
Hi, currently off grid again, hope to get to this next week. |
Decomposing something into simpler components should in general allow more versatile ways to combine them, so I would say yes :)
Add this to the list of problems then, caused by the downcasting mechanism! |
No longer in V2. |
Derived dimension types became really long with renaming
units::exp
tounits::exponent
. Let's try to find a better alternative.The text was updated successfully, but these errors were encountered: