From 6ad831b573e4d8e69fdd4f787122d35d69877b67 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 19 Apr 2024 16:14:34 +0100 Subject: [PATCH] docs: 2.2 release updated with `mag_ratio` --- docs/blog/posts/2.2.0-released.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/blog/posts/2.2.0-released.md b/docs/blog/posts/2.2.0-released.md index 02e23690..2329bfc5 100644 --- a/docs/blog/posts/2.2.0-released.md +++ b/docs/blog/posts/2.2.0-released.md @@ -372,3 +372,28 @@ inside of the `mp_units::si` subnamespace and not in `mp_units::isq` like it was (**breaking change**). Also, the header itself was split into smaller pieces that improve C++20 modules definitions. + + +## `ratio` made an implementation detail of the library + +We decided not to expose `ratio` and associated types in the public interface of the library +(**breaking change**). Standardization of it could be problematic as we have +[`std::ratio`](https://en.cppreference.com/w/cpp/numeric/ratio/ratio) already. + +Alternatively, we introduced a new helper called `mag_ratio` to provide the magnitude of the unit +defined in terms of a rational conversion factor. Here is a comparison of the code with previous +and current definitions: + +=== "Now" + + ```cpp + inline constexpr struct yard : named_unit<"yd", mag_ratio<9'144, 10'000> * si::metre> {} yard; + inline constexpr struct foot : named_unit<"ft", mag_ratio<1, 3> * yard> {} foot; + ``` + +=== "Before" + + ```cpp + inline constexpr struct yard : named_unit<"yd", mag * si::metre> {} yard; + inline constexpr struct foot : named_unit<"ft", mag * yard> {} foot; + ```