forked from mpusz/mp-units
refactor: quantity::count() renamed to quantity::number()
Resolves #259
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- (!) refactor: `ScalableNumber` renamed to `QuantityValue`
|
||||
- (!) refactor: output stream operators moved to the `units/quantity_io.h` header file
|
||||
- (!) refactor: Refactored the library file tree
|
||||
- (!) refactor: `quantity::count()` renamed to `quantity::number()`
|
||||
- refactor: quantity (kind) point updated to reflect latest changes to `quantity`
|
||||
- refactor: basic concepts, `quantity` and `quantity_cast` refactored
|
||||
- refactor: `abs()` definition refactored to be more explicit about the return type
|
||||
|
||||
@@ -179,7 +179,7 @@ code will not compile::
|
||||
|
||||
To make it compile fine we have to either explicitly get the value stored in the quantity::
|
||||
|
||||
auto v = std::exp(quantity_cast<one>(10_q_m / 5_q_m).count());
|
||||
auto v = std::exp(quantity_cast<one>(10_q_m / 5_q_m).number());
|
||||
|
||||
or use a mathematical wrapper function from `units` namespace::
|
||||
|
||||
@@ -188,4 +188,4 @@ or use a mathematical wrapper function from `units` namespace::
|
||||
.. important::
|
||||
|
||||
Always remember to explicitly cast the quantity to the destination unit with `quantity_cast` before
|
||||
calling `quantity::count()`!
|
||||
calling `quantity::number()`!
|
||||
|
||||
@@ -336,7 +336,7 @@ will print ``50 %`` to the console output.
|
||||
|
||||
Again, according to the ISO definition "such quantities convey more information than a
|
||||
number". This is exactly what we observe in the above example. The value stored inside
|
||||
the quantity, the text output, and the value returned by the `quantity::count()` member
|
||||
the quantity, the text output, and the value returned by the `quantity::number()` member
|
||||
function is ``50`` rather than ``0.5``. It means that dimensionless quantities behave
|
||||
like all other quantities and store the value in terms of a ratio of a coherent unit.
|
||||
This allows us to not loose precision when we divide quantities of the same dimensions
|
||||
|
||||
@@ -11,7 +11,7 @@ provide the following:
|
||||
- ``dimension`` mapping the source with target dimension type
|
||||
- ``unit`` mapping the source with target unit type
|
||||
- ``rep`` mapping the source with target representation type
|
||||
- a static member function ``count(T)`` that returns the raw value/magnitude of the quantity.
|
||||
- a static member function ``number(T)`` that returns the raw value/magnitude of the quantity.
|
||||
|
||||
For example, to provide support for the ``std::chrono::duration`` it is enough to define::
|
||||
|
||||
@@ -26,7 +26,7 @@ For example, to provide support for the ``std::chrono::duration`` it is enough t
|
||||
using dimension = isq::si::dim_time;
|
||||
using unit = downcast_unit<dimension, ratio(Period::num, Period::den)>;
|
||||
using rep = Rep;
|
||||
[[nodiscard]] static constexpr rep count(const std::chrono::duration<Rep, Period>& q) { return q.count(); }
|
||||
[[nodiscard]] static constexpr rep number(const std::chrono::duration<Rep, Period>& q) { return q.count(); }
|
||||
};
|
||||
|
||||
} // namespace units
|
||||
@@ -56,7 +56,7 @@ such an explicit conversion::
|
||||
|
||||
For external quantity point-like types, `quantity_point_like_traits` is also provided.
|
||||
It works just like `quantity_like_traits`, except that
|
||||
``count(T)`` is replaced with ``relative(T)`` that returns the `QuantityLike` value.
|
||||
``number(T)`` is replaced with ``relative(T)`` that returns the `QuantityLike` value.
|
||||
|
||||
Similar to `quantity` and `quantity_kind`, `quantity_point` and `quantity_kind_point`
|
||||
provide a deduction guide from `QuantityPointLike`::
|
||||
|
||||
@@ -4,7 +4,7 @@ Working with Legacy Interfaces
|
||||
==============================
|
||||
|
||||
In case we are working with a legacy/unsafe interface we may be forced to
|
||||
extract the :term:`value of a quantity` with :func:`quantity::count()`
|
||||
extract the :term:`value of a quantity` with :func:`quantity::number()`
|
||||
(in addition
|
||||
to the quantity of a `quantity_point` with :func:`quantity_point::relative()`,
|
||||
or the quantity of a `quantity_kind` with :func:`quantity_kind::common()`,
|
||||
@@ -38,18 +38,18 @@ and pass it to the library's output:
|
||||
void print_eta(Length auto d, Time auto t)
|
||||
{
|
||||
Speed auto v = avg_speed(d, t);
|
||||
legacy::print_eta(quantity_cast<si::metre_per_second>(v).count());
|
||||
legacy::print_eta(quantity_cast<si::metre_per_second>(v).number());
|
||||
}
|
||||
|
||||
template<QuantityPoint QP>
|
||||
requires Length<typename QP::quantity_type>
|
||||
void set_path_position(QP p)
|
||||
{
|
||||
legacy::set_path_position(quantity_point_cast<si::metre>(p).relative().count());
|
||||
legacy::set_path_position(quantity_point_cast<si::metre>(p).relative().number());
|
||||
}
|
||||
|
||||
.. important::
|
||||
|
||||
When dealing with a quantity of an unknown ``auto`` type please remember
|
||||
to always use `quantity_cast` to cast it to a desired unit before calling
|
||||
`quantity::count()` and passing the raw value to the legacy/unsafe interface.
|
||||
`quantity::number()` and passing the raw value to the legacy/unsafe interface.
|
||||
|
||||
@@ -64,7 +64,7 @@ Operations On Unknown Dimensions And Their Units
|
||||
For some cases we can eliminate the need to predefine a specific dimension and just use
|
||||
the `unknown_dimension` instead. Let's play with the previous example a bit::
|
||||
|
||||
static_assert(result.count() == 72);
|
||||
static_assert(result.number() == 72);
|
||||
|
||||
As we can see the value stored in this quantity can be easily obtained and contains a
|
||||
correct result. However, if we try to print its value to the text output we will get::
|
||||
|
||||
Reference in New Issue
Block a user