refactor: quantity::count() renamed to quantity::number()

Resolves #259
This commit is contained in:
Mateusz Pusz
2021-03-19 06:47:37 +01:00
parent bcaf252dec
commit 901b09fd52
26 changed files with 283 additions and 282 deletions

View File

@@ -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`::

View File

@@ -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.

View File

@@ -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::