-
Notifications
You must be signed in to change notification settings - Fork 89
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
docs(ref): document mp_units.core
#628
base: master
Are you sure you want to change the base?
Conversation
This is great! Thanks! Regarding magnitudes, please note that they are meant to be implementation-defined. Only a few user-facing API things are public (construction helpers (mag, mag_ratio, and mag_power), concept, operators, magnitude<...> where ... is implementation-defined). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is huge!!! Lots of great work! Thank you!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we specify that some public identifiers should not be exported from the std
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading https://wg21.link/std.modules, it seems like there's no way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will ask LWG members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping in mid-stream here -- is there a problem with marking them as exposition only? That basically says -- we're going to act like this thing exists in the standard, but we might implement it differently or call it something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exposition-only is not a solution, as I wrote in the LWG reflector.
\label{term.quantity.type} | ||
A \defnadj{quantity}{type} | ||
is a type \tcode{\placeholder{Q}} | ||
that is a specialization of \tcode{quantity} or \tcode{quantity_point}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some users that derive from quantity already. We support this in mp-units with derived_from. Should we remove this support?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this support?
I've always been against it.
Do you have the related issue/PR numbers?
I hope to convince you to do that with my TBD review here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is controversial for me as well. In C++ we typically discourage people from inheriting from std
types. It would be great if we could find a better solution here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most glaring issue is that for a parameter constrained with
std::derived_from<quantity>
or std::derived_from<quantity_point>
,
the implementation doesn't convert to the quantity
base subobject.
For example, in operator+
:
template<std::derived_from<quantity> Q, auto R2, typename Rep2>
requires detail::CommonlyInvocableQuantities<std::plus<>, quantity, quantity<R2, Rep2>>
[[nodiscard]] friend constexpr Quantity auto operator+(const Q& lhs, const quantity<R2, Rep2>& rhs)
{
using ret = detail::common_quantity_for<std::plus<>, quantity, quantity<R2, Rep2>>;
const ret ret_lhs(lhs);
We need this conversion from Q
, type of lhs
, to ret
,
to be the same as ret(static_cast<const quantity&>(lhs))
.
The implementation doesn't do that (like as-variant
),
so we need wording to require those parameter types
to not hide members
and prevent conversions like the above to have a different meaning.
Perhaps by requiring Q
to behave as-if the base template in the specified wording
(e.g., by borrowing https://eel.is/c++draft/namespace.std#2.2).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not oppose removing the support for deriving from a quantity
.
05ab0a8
to
8bf5db5
Compare
Could you please not squash or rebase the branch? It is impossible to track what changes between commits this way. I need to start reviewing all 2500 lines from scratch as I do not know what has changed. Maybe provide something for merge and open another PR with additional changes? |
This comment was marked as outdated.
This comment was marked as outdated.
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
I try to review in LatTeX as it is easier to provide comments that way, and I also need to learn the syntax. |
requires(sizeof...(Den) <= 1 && @\exposidnc{valid-ratio}@(Num, Den...) && @\exposidnc{positive-ratio}@(Num, Den...) && | ||
!@\exposidnc{ratio-one}@(Num, Den...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan also to provide valid-ratio
, positive-ratio
, and ratio-one
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or better.
This is part of:
This is also blocked on [...]
and a number of minor points which I'll review later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I fixed this with commit 6d64c98.
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
Co-authored-by: Mateusz Pusz <[email protected]>
\ref{qty.helpers} & Helpers & \tcode{mp_units.core} \\ | ||
\ref{qty.traits} & Traits & \\ | ||
\ref{qty.concepts} & Concepts & \\ | ||
\ref{qty.types} & Types & \\ | ||
\ref{qty.compat} & Compatibility & \\ | ||
\ref{qty.one} & Dimension one & \\ \rowsep | ||
\ref{qty.expr.temp} & Expression template & \\ | ||
\ref{qty.dim} & Dimension & \\ | ||
\ref{qty.spec} & Quantity specification & \\ | ||
\ref{qty.unit.mag} & Unit magnitude & \\ | ||
\ref{qty.unit} & Unit & \\ | ||
\ref{qty.ref} & Reference & \\ | ||
\ref{qty.rep} & Representation & \\ | ||
\ref{qty.traits} & Quantity traits & \\ | ||
\ref{qty} & Class template \tcode{quantity} & \\ | ||
\ref{qty.pt.orig} & Point origin & \\ | ||
\ref{qty.pt} & Class template \tcode{quantity_point} & \\ \rowsep | ||
\ref{qty.systems} & Systems & \tcode{mp_units.systems} \\ | ||
\ref{qty.chrono} & \tcode{std::chrono} compatibility & \\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, [qties] has many top-level subclauses (.18).
And we're still missing the specification of the module mp_units.system
.
It currently beats the C++ Standard library Clauses', of which these have the most:
[support] (.13), [utilities] (.16), [algorithms] (.12), [time] (.15), [input.output] (.13), [re] (.12), and [thread] (.11).
I think we should try to leave the top-level subclauses
for the domain and programming entities
that are most indispensable for the general problem but not our particular solution.
That'd mean moving 5.6 "Expression template" under 5.5 "Helpers"
(though indispensable to our particular solution,
it's not for the general problem of a "quantities and units library").
Also moving 5.9 "Unit magnitude" under 5.10 "Unit"
(in the theory, a unit is a quantity chosen by convention.
The unit magnitude here is a programming concept for the compile-time benefits).
It should be possible to dissolve 5.13 "Quantity values".
quantity_values
can be moved under 5.12 "Representation".
And if it isn't added under ::std
, it can then be renamed to representation_values
(e.g., ::std::units::representation_values
).
QuantityLike
and QuantityPointLike
can then be moved
next to quantity
and quantity_point
, respectively.
Also, shouldn't these concepts be exposition only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, "Unit magnitude" should be under "Unit".
Expression template probably as well. We may also need to rename it, as some people already objected to the use of this term for our purposes. The general-purpose expression template library would have totally different interfaces and rules. Ours is DSL (Domain Specific) version of expression templates.
Also, shouldn't these concepts be exposition only?
Initially, I thought it might be useful for a user to assert if a custom type satisfies those requirements. This is also why RepresentationOf
still takes quantity_character
explicitly (even though not used by the framework anywhere). If you think it is not a good enough reason to make it public, we can convert it to an exposition-only concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expression template probably as well. We may also need to rename it, as some people already objected to the use of this term for our purposes. The general-purpose expression template library would have totally different interfaces and rules. Ours is DSL (Domain Specific) version of expression templates.
To me, it seems more like a computer algebra system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to dissolve 5.13 "Quantity values".
quantity_values
can be moved under 5.12 "Representation".
And if it isn't added under::std
, it can then be renamed torepresentation_values
(e.g.,::std::units::representation_values
).
QuantityLike
andQuantityPointLike
can then be moved
next toquantity
andquantity_point
, respectively.
You can already do this rename, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, it seems more like a computer algebra system.
I am not sure. It does not feel like a calculator 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 5.6 "Symbolic computations"?
template<typename T, template<@\seebelow@> typename U> | ||
consteval bool @\exposidnc{is-derived-from-specialization-of}@(); // \expos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpusz Please, try replacing all the "is derived from specialization of" variable templates with overloaded function templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but it seems that clang-18 and below are broken 😢
https://godbolt.org/z/GPEMq6TKM
friend consteval @\exposidnc{ratio}@ operator/(@\exposidnc{ratio}@ lhs, @\exposidnc{ratio}@ rhs) { return lhs* @\exposidnc{ratio}@{rhs.den, rhs.num}; } | ||
}; | ||
|
||
consteval bool is_integral(@\exposidnc{ratio}@ r) { return r.num % r.den == 0; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, were you referring to is_integral
?
I thought we were talking about ratio
.
is_integral
is currently unused, as is common_ratio
.
If those are not used after filling in the TBDs, they should be removed.
Otherwise, yeah, maybe they should be exposition only.
Let \tcode{lhs} be \tcode{utf8} for the last two constructors, | ||
and otherwise: | ||
\begin{codeblock} | ||
std::bit_cast<std::fixed_u8string<N>>(std::basic_fixed_string(portable)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I don't remember them changing the char
type and its literals to be ASCII/UTF-8 compatible.
I just checked https://en.cppreference.com/w/cpp/language/types#Character_types
and https://en.cppreference.com/w/cpp/language/character_literal#Explanation.
The latter points to https://en.cppreference.com/w/cpp/language/charset#Code_unit_and_literal_encoding,
which hasn't changed since C++98 and still says
The ordinary and wide literal encodings are otherwise implementation-defined.
Anyways, I'll leave it as std::bit_cast
.
Tell me if you'd prefer it to be changed to std::ranges::to
.
requires @\seebelownc@ | ||
struct @\libglobal{power}@ final { | ||
using factor = F; | ||
static constexpr @\exposidnc{ratio}@ exponent{Num, Den...}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think exponent
should be exposition only,
given that ratio
is exposition only.
We should also make factor
exposition only,
as we only care that the names per
and power
are not exposition only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, both factor
and exponent
should be exposition-only. We just want to reserve the class name so the implementations have a similar look and feel without mandating any particular implementation.
template<std::intmax_t Num, std::intmax_t Den, template<typename...> typename To, | ||
typename OneType, template<typename, typename> typename Pred = @\exposidnc{type-less}@, typename T> | ||
requires(Den != 0) | ||
consteval auto @\exposidnc{expr-pow}@(T); // \expos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to use (Den != 0)
instead of detail::non_zero<Den>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Someone added those math concepts but I also consider them often more an issue than help. If you are OK with that, I can remove them from the code and replace with proper expressions.
This is still a WIP:
This is also blocked on
a number of minor points which I'll review later.
There are some TBDs, mainly for algorithms which need wording.
These are:
Representation
concepts.sudo_cast
.Work left (besides the TBDs above):
system_reference
math.h
random.h