Replies: 11 comments 75 replies
-
quantity<metre / second> speed(123); and this will result with a type like: |
Beta Was this translation helpful? Give feedback.
-
Dimensions will be used by values as well: struct dim_length : base_dimension<"L"> {};
struct dim_time : base_dimension<"T"> {};
struct dim_frequency : decltype(1 / dim_time{}) {};
struct dim_area : decltype(dim_length{} * dim_length{}) {};
struct dim_volume : decltype(dim_area{} * dim_length{}) {};
struct dim_speed : decltype(dim_length{} / dim_time{}) {};
struct dim_acceleration : decltype(dim_speed{} / dim_time{}) {}; |
Beta Was this translation helpful? Give feedback.
-
Here is some dimensional analysis that works already in my code: static_assert(is_of_type<1 / dim_time{}, derived_dimension<dim_one, per<dim_time>>>);
static_assert(is_of_type<1 / (1 / dim_time{}), dim_time>);
static_assert(is_of_type<dim_one{} * dim_time{}, dim_time>);
static_assert(is_of_type<dim_time{} * dim_one{}, dim_time>);
static_assert(is_of_type<dim_one{} * (1 / dim_time{}), derived_dimension<dim_one, per<dim_time>>>);
static_assert(is_of_type<1 / dim_time{} * dim_one{}, derived_dimension<dim_one, per<dim_time>>>);
static_assert(is_of_type<dim_length{} * dim_time{}, derived_dimension<dim_length, dim_time>>);
static_assert(is_of_type<dim_length{} * dim_length{}, derived_dimension<pow<dim_length, 2>>>);
static_assert(is_of_type<dim_length{} * dim_length{} * dim_time{}, derived_dimension<pow<dim_length, 2>, dim_time>>);
static_assert(is_of_type<dim_length{} * dim_time{} * dim_length{}, derived_dimension<pow<dim_length, 2>, dim_time>>);
static_assert(is_of_type<dim_length{} * (dim_time{} * dim_length{}), derived_dimension<pow<dim_length, 2>, dim_time>>);
static_assert(is_of_type<dim_time{} * (dim_length{} * dim_length{}), derived_dimension<pow<dim_length, 2>, dim_time>>);
static_assert(is_of_type<1 / dim_time{} * dim_length{}, derived_dimension<dim_length, per<dim_time>>>);
static_assert(is_of_type<1 / dim_time{} * dim_time{}, dim_one>);
static_assert(is_of_type<dim_time{} / dim_one{}, dim_time>);
static_assert(is_of_type<1 / dim_time{} / dim_one{}, derived_dimension<dim_one, per<dim_time>>>);
static_assert(is_of_type<dim_length{} / dim_time{} * dim_time{}, dim_length>);
static_assert(is_of_type<1 / dim_time{} * (1 / dim_time{}), derived_dimension<dim_one, per<pow<dim_time, 2>>>>);
static_assert(is_of_type<1 / (dim_time{} * dim_time{}), derived_dimension<dim_one, per<pow<dim_time, 2>>>>);
static_assert(is_of_type<1 / (1 / (dim_time{} * dim_time{})), derived_dimension<pow<dim_time, 2>>>);
static_assert(is_of_type<dim_length{} / dim_time{} * (1 / dim_time{}), derived_dimension<dim_length, per<pow<dim_time, 2>>>>);
static_assert(is_of_type<dim_length{} / dim_time{} * (dim_length{} / dim_time{}), derived_dimension<pow<dim_length, 2>, per<pow<dim_time, 2>>>>);
static_assert(is_of_type<dim_length{} / dim_time{} * (dim_time{} / dim_length{}), dim_one>); |
Beta Was this translation helpful? Give feedback.
-
Derived units and then derived references will be created in a similar way. |
Beta Was this translation helpful? Give feedback.
-
Note that the Good:
Bad:
quantity_of<dim_acceleration> auto acceleration = 123 * (metre / second);
template<UnitOf<dim_length> U, Representation Rep = double>
using length = quantity<dim_length, U, Rep>; // not possible now as there is no first parameter Should we provide more safety and more readable types like |
Beta Was this translation helpful? Give feedback.
-
How do you feel about: inline constexpr second second; ? We could do the same to dimensions to not have to type |
Beta Was this translation helpful? Give feedback.
-
I am aware that the quantity could be specified as: template<Reference auto& R>
struct quantity; which would allow me to work on values and allow things like: inline constexpr auto dim_speed = dim_length / dim_time; rather than: struct dim_speed : decltype(dim_length{} / dim_time{}) {};
inline constexpr dim_speed dim_speed; but on the other hand, it is much harder to construct expression templates that are easy to understand with such an approach. @JohelEGP, I think you are working on something like that, right? |
Beta Was this translation helpful? Give feedback.
-
What do you think about the usage of the indexing operator usage to specify a unit? |
Beta Was this translation helpful? Give feedback.
-
Unlike it is done in other libraries, the design still (the same as it is done currently) does not get a dimension for a unit type. I want to keep unit definitions separate (i.e. all ratios of time units) from binding them to specific dimensions. That way, I will not have to define that a minute is 60 seconds again if I decide to use seconds as well as the unit for length in some natural units system. There are some cases where different dimensions share the same unit and it should be easy to do the binding without the need to redefine all the units. However, this again creates name conflicts. For example, in the code provided, we have a |
Beta Was this translation helpful? Give feedback.
-
In the discussion thread above, we touched on a very important point of compatibility of equivalent dimensions and units. Now, without the downcasting facility, we will have much more intermediate temporary types than before. Consider: auto s = 100 * length[m] / (20 * time[s]) + 5 * speed[m/s];
auto f = 10 / (1 * time[s]) + 2 * frequency[Hz]; What should be the result of the above equations? Should both of them compile as they are, or maybe we should require explicit casts/conversions to derived types to make them work? For example, something like this: auto s = quantity_cast<speed>(100 * length[m] / (20 * time[s])) + 5 * speed[m/s];
auto f = quantity_cast<frequency>(10 / (1 * time[s])) + 2 * frequency[Hz]; |
Beta Was this translation helpful? Give feedback.
-
Should the |
Beta Was this translation helpful? Give feedback.
-
Hi,
As you know, I have been working on a new library design for a while. It took me longer than I initially thought, as it started with #281 but ended up with a much deeper rework. It still is not done, and I am far from determining the final design.
Here are some rough ideas as the source for discussion: https://godbolt.org/z/ddPWhcKW3.
quantity
will, of course, getRep
as the second argument in the final design.Everyone, your feedback at this stage is greatly appreciated! 😃 Please answer in the threads below or create a new one for a discussion on a new idea.
This will break our user's code in many places, so it is a really serious change. Before we merge the changes to mainline, I want to make sure the change is for the better and not for the worse. Please upvote whatever you like here or provide feedback on why it is not the case. Maybe we can improve that...
Beta Was this translation helpful? Give feedback.
All reactions