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

@ -4,6 +4,7 @@
- (!) refactor: `ScalableNumber` renamed to `QuantityValue` - (!) refactor: `ScalableNumber` renamed to `QuantityValue`
- (!) refactor: output stream operators moved to the `units/quantity_io.h` header file - (!) refactor: output stream operators moved to the `units/quantity_io.h` header file
- (!) refactor: Refactored the library file tree - (!) 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: quantity (kind) point updated to reflect latest changes to `quantity`
- refactor: basic concepts, `quantity` and `quantity_cast` refactored - refactor: basic concepts, `quantity` and `quantity_cast` refactored
- refactor: `abs()` definition refactored to be more explicit about the return type - refactor: `abs()` definition refactored to be more explicit about the return type

View File

@ -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:: 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:: or use a mathematical wrapper function from `units` namespace::
@ -188,4 +188,4 @@ or use a mathematical wrapper function from `units` namespace::
.. important:: .. important::
Always remember to explicitly cast the quantity to the destination unit with `quantity_cast` before Always remember to explicitly cast the quantity to the destination unit with `quantity_cast` before
calling `quantity::count()`! calling `quantity::number()`!

View File

@ -336,7 +336,7 @@ will print ``50 %`` to the console output.
Again, according to the ISO definition "such quantities convey more information than a 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 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 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. 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 This allows us to not loose precision when we divide quantities of the same dimensions

View File

@ -11,7 +11,7 @@ provide the following:
- ``dimension`` mapping the source with target dimension type - ``dimension`` mapping the source with target dimension type
- ``unit`` mapping the source with target unit type - ``unit`` mapping the source with target unit type
- ``rep`` mapping the source with target representation 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:: 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 dimension = isq::si::dim_time;
using unit = downcast_unit<dimension, ratio(Period::num, Period::den)>; using unit = downcast_unit<dimension, ratio(Period::num, Period::den)>;
using rep = Rep; 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 } // namespace units
@ -56,7 +56,7 @@ such an explicit conversion::
For external quantity point-like types, `quantity_point_like_traits` is also provided. For external quantity point-like types, `quantity_point_like_traits` is also provided.
It works just like `quantity_like_traits`, except that 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` Similar to `quantity` and `quantity_kind`, `quantity_point` and `quantity_kind_point`
provide a deduction guide from `QuantityPointLike`:: 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 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 (in addition
to the quantity of a `quantity_point` with :func:`quantity_point::relative()`, to the quantity of a `quantity_point` with :func:`quantity_point::relative()`,
or the quantity of a `quantity_kind` with :func:`quantity_kind::common()`, 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) void print_eta(Length auto d, Time auto t)
{ {
Speed auto v = avg_speed(d, 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> template<QuantityPoint QP>
requires Length<typename QP::quantity_type> requires Length<typename QP::quantity_type>
void set_path_position(QP p) 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:: .. important::
When dealing with a quantity of an unknown ``auto`` type please remember 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 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 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:: 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 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:: correct result. However, if we try to print its value to the text output we will get::

View File

@ -36,7 +36,7 @@ inline constexpr std::common_type_t<typename Target::rep, typename Source::rep>
typedef std::common_type_t<typename Target::rep, typename Source::rep> rep; typedef std::common_type_t<typename Target::rep, typename Source::rep> rep;
typedef units::quantity<typename Source::dimension, typename Source::unit, rep> source; typedef units::quantity<typename Source::dimension, typename Source::unit, rep> source;
typedef units::quantity<typename Target::dimension, typename Target::unit, rep> target; typedef units::quantity<typename Target::dimension, typename Target::unit, rep> target;
return target{source{1}}.count(); return target{source{1}}.number();
} }
} // namespace } // namespace
@ -58,6 +58,6 @@ int main()
std::cout << "conversion factor from lengthA::unit of " std::cout << "conversion factor from lengthA::unit of "
<< units_str(lengthA).standard() << " to lengthB::unit of " << units_str(lengthB).standard() << " :\n\n" << units_str(lengthA).standard() << " to lengthB::unit of " << units_str(lengthB).standard() << " :\n\n"
<< "lengthB.count( " << lengthB.count() << " ) == lengthA.count( " << lengthA.count() << "lengthB.number( " << lengthB.number() << " ) == lengthA.number( " << lengthA.number()
<< " ) * conversion_factor( " << conversion_factor(lengthB, lengthA) << " )\n"; << " ) * conversion_factor( " << conversion_factor(lengthB, lengthA) << " )\n";
} }

View File

@ -35,7 +35,7 @@ inline constexpr std::common_type_t<typename Target::rep, typename Source::rep>
typedef std::common_type_t<typename Target::rep, typename Source::rep> rep; typedef std::common_type_t<typename Target::rep, typename Source::rep> rep;
typedef units::quantity<typename Source::dimension, typename Source::unit, rep> source; typedef units::quantity<typename Source::dimension, typename Source::unit, rep> source;
typedef units::quantity<typename Target::dimension, typename Target::unit, rep> target; typedef units::quantity<typename Target::dimension, typename Target::unit, rep> target;
return target{source{1}}.count(); return target{source{1}}.number();
} }
} // namespace } // namespace
@ -55,6 +55,6 @@ int main()
std::cout << fmt::format("therefore ratio lengthA / lengthB == {}\n\n", lengthA / lengthB); std::cout << fmt::format("therefore ratio lengthA / lengthB == {}\n\n", lengthA / lengthB);
std::cout << fmt::format("conversion factor from lengthA::unit of {:%q} to lengthB::unit of {:%q}:\n\n", lengthA, lengthB) std::cout << fmt::format("conversion factor from lengthA::unit of {:%q} to lengthB::unit of {:%q}:\n\n", lengthA, lengthB)
<< fmt::format("lengthB.count( {} ) == lengthA.count( {} ) * conversion_factor( {} )\n", << fmt::format("lengthB.number( {} ) == lengthA.number( {} ) * conversion_factor( {} )\n",
lengthB.count(), lengthA.count(), conversion_factor(lengthB, lengthA)); lengthB.number(), lengthA.number(), conversion_factor(lengthB, lengthA));
} }

View File

@ -272,7 +272,7 @@ namespace units {
rep_format_specs const & rspecs, unit_format_specs const & uspecs, rep_format_specs const & rspecs, unit_format_specs const & uspecs,
LocaleRef lc LocaleRef lc
): ):
out(o), val(q.count()), global_specs(gspecs), rep_specs(rspecs), unit_specs(uspecs), loc(lc) out(o), val(q.number()), global_specs(gspecs), rep_specs(rspecs), unit_specs(uspecs), loc(lc)
{ {
} }
@ -491,7 +491,7 @@ public:
// deal with quantity content // deal with quantity content
if(begin == end || *begin == '}') { if(begin == end || *begin == '}') {
// default format should print value followed by the unit separated with 1 space // default format should print value followed by the unit separated with 1 space
to_quantity_buffer = units::detail::format_units_quantity_value<CharT>(to_quantity_buffer, q.count(), rep_specs, ctx.locale()); to_quantity_buffer = units::detail::format_units_quantity_value<CharT>(to_quantity_buffer, q.number(), rep_specs, ctx.locale());
constexpr auto symbol = units::detail::unit_text<Dimension, Unit>(); constexpr auto symbol = units::detail::unit_text<Dimension, Unit>();
if(symbol.standard().size()) { if(symbol.standard().size()) {
*to_quantity_buffer++ = CharT(' '); *to_quantity_buffer++ = CharT(' ');

View File

@ -34,7 +34,7 @@ namespace detail {
template<typename CharT, class Traits, typename D, typename U, typename Rep> template<typename CharT, class Traits, typename D, typename U, typename Rep>
void to_stream(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>& q) void to_stream(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>& q)
{ {
os << q.count(); os << q.number();
constexpr auto symbol = detail::unit_text<D, U>(); constexpr auto symbol = detail::unit_text<D, U>();
if constexpr (!symbol.standard().empty()) { if constexpr (!symbol.standard().empty()) {
os << " " << symbol.standard(); os << " " << symbol.standard();
@ -45,7 +45,7 @@ void to_stream(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>&
template<typename CharT, typename Traits, typename D, typename U, typename Rep> template<typename CharT, typename Traits, typename D, typename U, typename Rep>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>& q) std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>& q)
requires requires { os << q.count(); } requires requires { os << q.number(); }
{ {
if(os.width()) { if(os.width()) {
// std::setw() applies to the whole quantity output so it has to be first put into std::string // std::setw() applies to the whole quantity output so it has to be first put into std::string

View File

@ -414,7 +414,7 @@ template<typename T>
requires Dimension<typename quantity_like_traits<T>::dimension>; requires Dimension<typename quantity_like_traits<T>::dimension>;
requires Unit<typename quantity_like_traits<T>::unit>; requires Unit<typename quantity_like_traits<T>::unit>;
requires QuantityValue<typename quantity_like_traits<T>::rep>; requires QuantityValue<typename quantity_like_traits<T>::rep>;
{ quantity_like_traits<T>::count(q) } -> std::convertible_to<typename quantity_like_traits<T>::rep>; { quantity_like_traits<T>::number(q) } -> std::convertible_to<typename quantity_like_traits<T>::rep>;
} }
inline constexpr bool is_quantity_like<T> = true; inline constexpr bool is_quantity_like<T> = true;

View File

@ -33,7 +33,7 @@ struct quantity_like_traits<std::chrono::duration<Rep, Period>> {
using dimension = isq::si::dim_time; using dimension = isq::si::dim_time;
using unit = downcast_unit<dimension, ratio(Period::num, Period::den)>; using unit = downcast_unit<dimension, ratio(Period::num, Period::den)>;
using rep = Rep; 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(); }
}; };
template<typename C, typename Rep, typename Period> template<typename C, typename Rep, typename Period>

View File

@ -76,7 +76,7 @@ struct quantity_values {
* @brief Provides support for external quantity-like types * @brief Provides support for external quantity-like types
* *
* The type trait should provide the following nested type aliases: @c dimension, @c unit, @c rep, * The type trait should provide the following nested type aliases: @c dimension, @c unit, @c rep,
* and a static member function @c count(T) that will return the raw value of the quantity. * and a static member function @c number(T) that will return the raw value of the quantity.
* *
* Usage example can be found in @c units/chrono.h header file. * Usage example can be found in @c units/chrono.h header file.
* *

View File

@ -41,7 +41,7 @@ namespace units {
*/ */
template<std::intmax_t Num, std::intmax_t Den = 1, Quantity Q> template<std::intmax_t Num, std::intmax_t Den = 1, Quantity Q>
requires detail::non_zero<Den> requires detail::non_zero<Den>
[[nodiscard]] inline auto pow(const Q& q) noexcept requires requires { std::pow(q.count(), 1.0); } [[nodiscard]] inline auto pow(const Q& q) noexcept requires requires { std::pow(q.number(), 1.0); }
{ {
using rep = TYPENAME Q::rep; using rep = TYPENAME Q::rep;
if constexpr (Num == 0) { if constexpr (Num == 0) {
@ -50,7 +50,7 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Quantity Q>
using dim = dimension_pow<typename Q::dimension, Num, Den>; using dim = dimension_pow<typename Q::dimension, Num, Den>;
using unit = downcast_unit<dim, pow<Num, Den>(Q::unit::ratio)>; using unit = downcast_unit<dim, pow<Num, Den>(Q::unit::ratio)>;
return quantity<dim, unit, rep>( return quantity<dim, unit, rep>(
static_cast<rep>(std::pow(q.count(), static_cast<double>(Num) / static_cast<double>(Den)))); static_cast<rep>(std::pow(q.number(), static_cast<double>(Num) / static_cast<double>(Den))));
} }
} }
@ -64,12 +64,12 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Quantity Q>
*/ */
template<Quantity Q> template<Quantity Q>
[[nodiscard]] inline Quantity auto sqrt(const Q& q) noexcept [[nodiscard]] inline Quantity auto sqrt(const Q& q) noexcept
requires requires { std::sqrt(q.count()); } requires requires { std::sqrt(q.number()); }
{ {
using dim = dimension_pow<typename Q::dimension, 1, 2>; using dim = dimension_pow<typename Q::dimension, 1, 2>;
using unit = downcast_unit<dim, sqrt(Q::unit::ratio)>; using unit = downcast_unit<dim, sqrt(Q::unit::ratio)>;
using rep = TYPENAME Q::rep; using rep = TYPENAME Q::rep;
return quantity<dim, unit, rep>(static_cast<rep>(std::sqrt(q.count()))); return quantity<dim, unit, rep>(static_cast<rep>(std::sqrt(q.number())));
} }
/** /**
@ -82,12 +82,12 @@ template<Quantity Q>
*/ */
template<Quantity Q> template<Quantity Q>
[[nodiscard]] inline Quantity auto cbrt(const Q& q) noexcept [[nodiscard]] inline Quantity auto cbrt(const Q& q) noexcept
requires requires { std::cbrt(q.count()); } requires requires { std::cbrt(q.number()); }
{ {
using dim = dimension_pow<typename Q::dimension, 1, 3>; using dim = dimension_pow<typename Q::dimension, 1, 3>;
using unit = downcast_unit<dim, cbrt(Q::unit::ratio)>; using unit = downcast_unit<dim, cbrt(Q::unit::ratio)>;
using rep = TYPENAME Q::rep; using rep = TYPENAME Q::rep;
return quantity<dim, unit, rep>(static_cast<rep>(std::cbrt(q.count()))); return quantity<dim, unit, rep>(static_cast<rep>(std::cbrt(q.number())));
} }
/** /**
@ -101,7 +101,7 @@ template<Quantity Q>
template<typename U, typename Rep> template<typename U, typename Rep>
[[nodiscard]] inline dimensionless<U, Rep> exp(const dimensionless<U, Rep>& q) [[nodiscard]] inline dimensionless<U, Rep> exp(const dimensionless<U, Rep>& q)
{ {
return quantity_cast<U>(dimensionless<one, Rep>(std::exp(quantity_cast<one>(q).count()))); return quantity_cast<U>(dimensionless<one, Rep>(std::exp(quantity_cast<one>(q).number())));
} }
/** /**
@ -112,9 +112,9 @@ template<typename U, typename Rep>
*/ */
template<typename D, typename U, typename Rep> template<typename D, typename U, typename Rep>
[[nodiscard]] inline quantity<D, U, Rep> abs(const quantity<D, U, Rep>& q) noexcept [[nodiscard]] inline quantity<D, U, Rep> abs(const quantity<D, U, Rep>& q) noexcept
requires requires { std::abs(q.count()); } requires requires { std::abs(q.number()); }
{ {
return quantity<D, U, Rep>(std::abs(q.count())); return quantity<D, U, Rep>(std::abs(q.number()));
} }
/** /**

View File

@ -149,31 +149,31 @@ public:
quantity(const Value& v) : value_(v) {} quantity(const Value& v) : value_(v) {}
template<safe_castable_to_<quantity> Q> template<safe_castable_to_<quantity> Q>
constexpr explicit(false) quantity(const Q& q) : value_(quantity_cast<quantity>(q).count()) {} constexpr explicit(false) quantity(const Q& q) : value_(quantity_cast<quantity>(q).number()) {}
template<QuantityLike Q> template<QuantityLike Q>
requires safe_castable_to_<quantity_like_type<Q>, quantity> requires safe_castable_to_<quantity_like_type<Q>, quantity>
constexpr explicit quantity(const Q& q) : quantity(quantity_like_type<Q>(quantity_like_traits<Q>::count(q))) {} constexpr explicit quantity(const Q& q) : quantity(quantity_like_type<Q>(quantity_like_traits<Q>::number(q))) {}
quantity& operator=(const quantity&) = default; quantity& operator=(const quantity&) = default;
quantity& operator=(quantity&&) = default; quantity& operator=(quantity&&) = default;
// data access // data access
[[nodiscard]] constexpr rep count() const noexcept { return value_; } [[nodiscard]] constexpr rep number() const noexcept { return value_; }
// member unary operators // member unary operators
[[nodiscard]] constexpr Quantity auto operator+() const [[nodiscard]] constexpr Quantity auto operator+() const
requires requires(rep v) { { +v } -> std::common_with<rep>; } requires requires(rep v) { { +v } -> std::common_with<rep>; }
{ {
using ret = quantity<D, U, decltype(+count())>; using ret = quantity<D, U, decltype(+number())>;
return ret(+count()); return ret(+number());
} }
[[nodiscard]] constexpr Quantity auto operator-() const [[nodiscard]] constexpr Quantity auto operator-() const
requires std::regular_invocable<std::negate<>, rep> requires std::regular_invocable<std::negate<>, rep>
{ {
using ret = quantity<D, U, decltype(-count())>; using ret = quantity<D, U, decltype(-number())>;
return ret(-count()); return ret(-number());
} }
constexpr quantity& operator++() constexpr quantity& operator++()
@ -205,14 +205,14 @@ public:
constexpr quantity& operator+=(const quantity& q) constexpr quantity& operator+=(const quantity& q)
requires requires(rep a, rep b) { { a += b } -> std::same_as<rep&>; } requires requires(rep a, rep b) { { a += b } -> std::same_as<rep&>; }
{ {
value_ += q.count(); value_ += q.number();
return *this; return *this;
} }
constexpr quantity& operator-=(const quantity& q) constexpr quantity& operator-=(const quantity& q)
requires requires(rep a, rep b) { { a -= b } -> std::same_as<rep&>; } requires requires(rep a, rep b) { { a -= b } -> std::same_as<rep&>; }
{ {
value_ -= q.count(); value_ -= q.number();
return *this; return *this;
} }
@ -227,7 +227,7 @@ public:
constexpr quantity& operator*=(const dimensionless<units::one, Rep2>& rhs) constexpr quantity& operator*=(const dimensionless<units::one, Rep2>& rhs)
requires requires(rep a, const Rep2 b) { { a *= b } -> std::same_as<rep&>; } requires requires(rep a, const Rep2 b) { { a *= b } -> std::same_as<rep&>; }
{ {
value_ *= rhs.count(); value_ *= rhs.number();
return *this; return *this;
} }
@ -243,8 +243,8 @@ public:
constexpr quantity& operator/=(const dimensionless<units::one, Rep2>& rhs) constexpr quantity& operator/=(const dimensionless<units::one, Rep2>& rhs)
requires requires(rep a, const Rep2 b) { { a /= b } -> std::same_as<rep&>; } requires requires(rep a, const Rep2 b) { { a /= b } -> std::same_as<rep&>; }
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<Rep2>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<Rep2>::zero());
value_ /= rhs.count(); value_ /= rhs.number();
return *this; return *this;
} }
@ -263,8 +263,8 @@ public:
requires (!floating_point_<rep>) && (!floating_point_<Rep2>) && requires (!floating_point_<rep>) && (!floating_point_<Rep2>) &&
requires(rep a, const Rep2 b) { { a %= b } -> std::same_as<rep&>; } requires(rep a, const Rep2 b) { { a %= b } -> std::same_as<rep&>; }
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<Rep2>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<Rep2>::zero());
value_ %= rhs.count(); value_ %= rhs.number();
return *this; return *this;
} }
@ -272,8 +272,8 @@ public:
requires (!floating_point_<rep>) && requires (!floating_point_<rep>) &&
requires(rep a, rep b) { { a %= b } -> std::same_as<rep&>; } requires(rep a, rep b) { { a %= b } -> std::same_as<rep&>; }
{ {
gsl_ExpectsAudit(q.count() != quantity_values<rep>::zero()); gsl_ExpectsAudit(q.number() != quantity_values<rep>::zero());
value_ %= q.count(); value_ %= q.number();
return *this; return *this;
} }
@ -284,14 +284,14 @@ public:
requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify
requires invoke_result_convertible_to_<rep, std::plus<>, rep, Value>; } // when Clang catches up. requires invoke_result_convertible_to_<rep, std::plus<>, rep, Value>; } // when Clang catches up.
{ {
return units::quantity(lhs.count() + rhs); return units::quantity(lhs.number() + rhs);
} }
template<typename Value> template<typename Value>
[[nodiscard]] friend constexpr Quantity auto operator+(const Value& lhs, const quantity& rhs) [[nodiscard]] friend constexpr Quantity auto operator+(const Value& lhs, const quantity& rhs)
requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify
requires invoke_result_convertible_to_<rep, std::plus<>, Value, rep>; } // when Clang catches up. requires invoke_result_convertible_to_<rep, std::plus<>, Value, rep>; } // when Clang catches up.
{ {
return units::quantity(lhs + rhs.count()); return units::quantity(lhs + rhs.number());
} }
template<typename Value> template<typename Value>
@ -299,14 +299,14 @@ public:
requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify
requires invoke_result_convertible_to_<rep, std::minus<>, rep, Value>; } // when Clang catches up. requires invoke_result_convertible_to_<rep, std::minus<>, rep, Value>; } // when Clang catches up.
{ {
return units::quantity(lhs.count() - rhs); return units::quantity(lhs.number() - rhs);
} }
template<typename Value> template<typename Value>
[[nodiscard]] friend constexpr Quantity auto operator-(const Value& lhs, const quantity& rhs) [[nodiscard]] friend constexpr Quantity auto operator-(const Value& lhs, const quantity& rhs)
requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify requires requires { requires !Quantity<Value>; requires is_same_v<unit, units::one>; // TODO: Simplify
requires invoke_result_convertible_to_<rep, std::minus<>, Value, rep>; } // when Clang catches up. requires invoke_result_convertible_to_<rep, std::minus<>, Value, rep>; } // when Clang catches up.
{ {
return units::quantity(lhs - rhs.count()); return units::quantity(lhs - rhs.number());
} }
template<typename Value> template<typename Value>
@ -315,7 +315,7 @@ public:
[[nodiscard]] friend constexpr Quantity auto operator*(const quantity& q, const Value& v) [[nodiscard]] friend constexpr Quantity auto operator*(const quantity& q, const Value& v)
{ {
using ret = quantity<D, U, std::invoke_result_t<std::multiplies<>, rep, Value>>; using ret = quantity<D, U, std::invoke_result_t<std::multiplies<>, rep, Value>>;
return ret(q.count() * v); return ret(q.number() * v);
} }
template<typename Value> template<typename Value>
@ -324,7 +324,7 @@ public:
[[nodiscard]] friend constexpr Quantity auto operator*(const Value& v, const quantity& q) [[nodiscard]] friend constexpr Quantity auto operator*(const Value& v, const quantity& q)
{ {
using ret = quantity<D, U, std::invoke_result_t<std::multiplies<>, Value, rep>>; using ret = quantity<D, U, std::invoke_result_t<std::multiplies<>, Value, rep>>;
return ret(v * q.count()); return ret(v * q.number());
} }
template<typename Value> template<typename Value>
@ -334,7 +334,7 @@ public:
{ {
gsl_ExpectsAudit(v != quantity_values<Value>::zero()); gsl_ExpectsAudit(v != quantity_values<Value>::zero());
using ret = quantity<D, U, std::invoke_result_t<std::divides<>, rep, Value>>; using ret = quantity<D, U, std::invoke_result_t<std::divides<>, rep, Value>>;
return ret(q.count() / v); return ret(q.number() / v);
} }
template<typename Value> template<typename Value>
@ -342,11 +342,11 @@ public:
invoke_result_convertible_to_<rep, std::divides<>, const Value&, rep> invoke_result_convertible_to_<rep, std::divides<>, const Value&, rep>
[[nodiscard]] friend constexpr Quantity auto operator/(const Value& v, const quantity& q) [[nodiscard]] friend constexpr Quantity auto operator/(const Value& v, const quantity& q)
{ {
gsl_ExpectsAudit(q.count() != quantity_values<rep>::zero()); gsl_ExpectsAudit(q.number() != quantity_values<rep>::zero());
using dim = dim_invert<D>; using dim = dim_invert<D>;
using ret_unit = downcast_unit<dim, inverse(U::ratio)>; using ret_unit = downcast_unit<dim, inverse(U::ratio)>;
using ret = quantity<dim, ret_unit, std::invoke_result_t<std::divides<>, Value, rep>>; using ret = quantity<dim, ret_unit, std::invoke_result_t<std::divides<>, Value, rep>>;
return ret(v / q.count()); return ret(v / q.number());
} }
template<typename Value> template<typename Value>
@ -356,15 +356,15 @@ public:
{ {
gsl_ExpectsAudit(v != quantity_values<Value>::zero()); gsl_ExpectsAudit(v != quantity_values<Value>::zero());
using ret = quantity<D, U, std::invoke_result_t<std::modulus<>, rep, Value>>; using ret = quantity<D, U, std::invoke_result_t<std::modulus<>, rep, Value>>;
return ret(q.count() % v); return ret(q.number() % v);
} }
[[nodiscard]] friend constexpr Quantity auto operator%(const quantity& lhs, const quantity& rhs) [[nodiscard]] friend constexpr Quantity auto operator%(const quantity& lhs, const quantity& rhs)
requires (!floating_point_<rep>) && is_same_v<unit, units::one> && requires (!floating_point_<rep>) && is_same_v<unit, units::one> &&
invoke_result_convertible_to_<rep, std::modulus<>, rep, rep> invoke_result_convertible_to_<rep, std::modulus<>, rep, rep>
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<rep>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<rep>::zero());
return units::quantity(lhs.count() % rhs.count()); return units::quantity(lhs.number() % rhs.number());
} }
[[nodiscard]] friend constexpr auto operator<=>(const quantity& lhs, const quantity& rhs) [[nodiscard]] friend constexpr auto operator<=>(const quantity& lhs, const quantity& rhs)
@ -373,7 +373,7 @@ public:
= default; = default;
#else #else
{ {
return lhs.count() <=> rhs.count(); return lhs.number() <=> rhs.number();
} }
#endif #endif
@ -393,7 +393,7 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
[[nodiscard]] constexpr Quantity auto operator+(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr Quantity auto operator+(const Q1& lhs, const Q2& rhs)
{ {
using ret = common_quantity_for<std::plus<>, Q1, Q2>; using ret = common_quantity_for<std::plus<>, Q1, Q2>;
return ret(ret(lhs).count() + ret(rhs).count()); return ret(ret(lhs).number() + ret(rhs).number());
} }
template<Quantity Q1, QuantityEquivalentTo<Q1> Q2> template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
@ -401,22 +401,22 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
[[nodiscard]] constexpr Quantity auto operator-(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr Quantity auto operator-(const Q1& lhs, const Q2& rhs)
{ {
using ret = common_quantity_for<std::minus<>, Q1, Q2>; using ret = common_quantity_for<std::minus<>, Q1, Q2>;
return ret(ret(lhs).count() - ret(rhs).count()); return ret(ret(lhs).number() - ret(rhs).number());
} }
template<Quantity Q1, Quantity Q2> template<Quantity Q1, Quantity Q2>
requires quantity_value_for_<std::multiplies<>, typename Q1::rep, typename Q2::rep> requires quantity_value_for_<std::multiplies<>, typename Q1::rep, typename Q2::rep>
[[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs)
{ {
return detail::make_quantity<Q1::reference * Q2::reference>(lhs.count() * rhs.count()); return detail::make_quantity<Q1::reference * Q2::reference>(lhs.number() * rhs.number());
} }
template<Quantity Q1, Quantity Q2> template<Quantity Q1, Quantity Q2>
requires quantity_value_for_<std::divides<>, typename Q1::rep, typename Q2::rep> requires quantity_value_for_<std::divides<>, typename Q1::rep, typename Q2::rep>
[[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs)
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<typename Q2::rep>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<typename Q2::rep>::zero());
return detail::make_quantity<Q1::reference / Q2::reference>(lhs.count() / rhs.count()); return detail::make_quantity<Q1::reference / Q2::reference>(lhs.number() / rhs.number());
} }
template<typename D1, typename U1, typename Rep1, typename U2, typename Rep2> template<typename D1, typename U1, typename Rep1, typename U2, typename Rep2>
@ -424,10 +424,10 @@ template<typename D1, typename U1, typename Rep1, typename U2, typename Rep2>
quantity_value_for_<std::modulus<>, Rep1, Rep2> quantity_value_for_<std::modulus<>, Rep1, Rep2>
[[nodiscard]] constexpr Quantity auto operator%(const quantity<D1, U1, Rep1>& lhs, const quantity<dim_one, U2, Rep2>& rhs) [[nodiscard]] constexpr Quantity auto operator%(const quantity<D1, U1, Rep1>& lhs, const quantity<dim_one, U2, Rep2>& rhs)
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<Rep2>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<Rep2>::zero());
using unit = downcast_unit<D1, U1::ratio * U2::ratio>; using unit = downcast_unit<D1, U1::ratio * U2::ratio>;
using ret = quantity<D1, unit, std::invoke_result_t<std::modulus<>, Rep1, Rep2>>; using ret = quantity<D1, unit, std::invoke_result_t<std::modulus<>, Rep1, Rep2>>;
return ret(lhs.count() % rhs.count()); return ret(lhs.number() % rhs.number());
} }
template<Quantity Q1, QuantityEquivalentTo<Q1> Q2> template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
@ -435,9 +435,9 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
quantity_value_for_<std::modulus<>, typename Q1::rep, typename Q2::rep> quantity_value_for_<std::modulus<>, typename Q1::rep, typename Q2::rep>
[[nodiscard]] constexpr Quantity auto operator%(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr Quantity auto operator%(const Q1& lhs, const Q2& rhs)
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<typename Q2::rep>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<typename Q2::rep>::zero());
using ret = common_quantity_for<std::modulus<>, Q1, Q2>; using ret = common_quantity_for<std::modulus<>, Q1, Q2>;
return ret(ret(lhs).count() % ret(rhs).count()); return ret(ret(lhs).number() % ret(rhs).number());
} }
template<Quantity Q1, QuantityEquivalentTo<Q1> Q2> template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
@ -445,7 +445,7 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
[[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs)
{ {
using cq = common_quantity<Q1, Q2>; using cq = common_quantity<Q1, Q2>;
return cq(lhs).count() <=> cq(rhs).count(); return cq(lhs).number() <=> cq(rhs).number();
} }
template<Quantity Q1, QuantityEquivalentTo<Q1> Q2> template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
@ -453,7 +453,7 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
[[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs) [[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs)
{ {
using cq = common_quantity<Q1, Q2>; using cq = common_quantity<Q1, Q2>;
return cq(lhs).count() == cq(rhs).count(); return cq(lhs).number() == cq(rhs).number();
} }
// type traits // type traits

View File

@ -121,17 +121,17 @@ template<Quantity To, typename D, typename U, scalable_with_<typename To::rep> R
constexpr auto c_ratio = detail::cast_ratio<quantity<D, U, Rep>, To>; constexpr auto c_ratio = detail::cast_ratio<quantity<D, U, Rep>, To>;
if constexpr (treat_as_floating_point<rep_type>) { if constexpr (treat_as_floating_point<rep_type>) {
return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.count()) * return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.number()) *
(static_cast<ratio_type>(c_ratio.num) * detail::fpow10<ratio_type>(c_ratio.exp) / static_cast<ratio_type>(c_ratio.den)))); (static_cast<ratio_type>(c_ratio.num) * detail::fpow10<ratio_type>(c_ratio.exp) / static_cast<ratio_type>(c_ratio.den))));
} }
else { else {
if constexpr (c_ratio.exp > 0) { if constexpr (c_ratio.exp > 0) {
return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.count()) * return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.number()) *
(static_cast<ratio_type>(c_ratio.num) * static_cast<ratio_type>(detail::ipow10(c_ratio.exp))) / (static_cast<ratio_type>(c_ratio.num) * static_cast<ratio_type>(detail::ipow10(c_ratio.exp))) /
static_cast<ratio_type>(c_ratio.den))); static_cast<ratio_type>(c_ratio.den)));
} }
else { else {
return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.count()) * return To(static_cast<TYPENAME To::rep>(static_cast<rep_type>(q.number()) *
static_cast<ratio_type>(c_ratio.num) / static_cast<ratio_type>(c_ratio.num) /
(static_cast<ratio_type>(c_ratio.den) * static_cast<ratio_type>(detail::ipow10(-c_ratio.exp))))); (static_cast<ratio_type>(c_ratio.den) * static_cast<ratio_type>(detail::ipow10(-c_ratio.exp)))));
} }

View File

@ -232,7 +232,7 @@ public:
constexpr quantity_kind& operator%=(const quantity_kind& qk) constexpr quantity_kind& operator%=(const quantity_kind& qk)
requires requires(quantity_type q) { q %= qk.common(); } requires requires(quantity_type q) { q %= qk.common(); }
{ {
gsl_ExpectsAudit(qk.common().count() != quantity_values<rep>::zero()); gsl_ExpectsAudit(qk.common().number() != quantity_values<rep>::zero());
q_ %= qk.common(); q_ %= qk.common();
return *this; return *this;
} }
@ -265,7 +265,7 @@ public:
[[nodiscard]] friend constexpr QuantityKind auto operator/(const Value& v, const quantity_kind& qk) [[nodiscard]] friend constexpr QuantityKind auto operator/(const Value& v, const quantity_kind& qk)
requires requires(quantity_type q) { { v / q } -> Quantity; } requires requires(quantity_type q) { { v / q } -> Quantity; }
{ {
gsl_ExpectsAudit(qk.common().count() != quantity_values<rep>::zero()); gsl_ExpectsAudit(qk.common().number() != quantity_values<rep>::zero());
return detail::downcasted_kind<quantity_kind>(v / qk.common()); return detail::downcasted_kind<quantity_kind>(v / qk.common());
} }
@ -325,7 +325,7 @@ template<QuantityKind QK, Quantity Q>
[[nodiscard]] constexpr QuantityKind auto operator/(const QK& lhs, const Q& rhs) [[nodiscard]] constexpr QuantityKind auto operator/(const QK& lhs, const Q& rhs)
requires requires { lhs.common() / rhs; } requires requires { lhs.common() / rhs; }
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<typename Q::rep>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<typename Q::rep>::zero());
return detail::downcasted_kind<QK>(lhs.common() / rhs); return detail::downcasted_kind<QK>(lhs.common() / rhs);
} }
@ -333,7 +333,7 @@ template<Quantity Q, QuantityKind QK>
[[nodiscard]] constexpr QuantityKind auto operator/(const Q& lhs, const QK& rhs) [[nodiscard]] constexpr QuantityKind auto operator/(const Q& lhs, const QK& rhs)
requires requires { lhs / rhs.common(); } requires requires { lhs / rhs.common(); }
{ {
gsl_ExpectsAudit(rhs.common().count() != quantity_values<typename QK::rep>::zero()); gsl_ExpectsAudit(rhs.common().number() != quantity_values<typename QK::rep>::zero());
return detail::downcasted_kind<QK>(lhs / rhs.common()); return detail::downcasted_kind<QK>(lhs / rhs.common());
} }
@ -348,7 +348,7 @@ template<QuantityKind QK, Dimensionless D>
[[nodiscard]] constexpr QuantityKind auto operator%(const QK& lhs, const D& rhs) [[nodiscard]] constexpr QuantityKind auto operator%(const QK& lhs, const D& rhs)
requires requires { lhs.common() % rhs; } requires requires { lhs.common() % rhs; }
{ {
gsl_ExpectsAudit(rhs.count() != quantity_values<typename D::rep>::zero()); gsl_ExpectsAudit(rhs.number() != quantity_values<typename D::rep>::zero());
return detail::make_quantity_kind<QK>(lhs.common() % rhs); return detail::make_quantity_kind<QK>(lhs.common() % rhs);
} }
@ -356,7 +356,7 @@ template<QuantityKind QK1, QuantityKindEquivalentTo<QK1> QK2>
[[nodiscard]] constexpr QuantityKind auto operator%(const QK1& lhs, const QK2& rhs) [[nodiscard]] constexpr QuantityKind auto operator%(const QK1& lhs, const QK2& rhs)
requires requires { lhs.common() % rhs.common(); } requires requires { lhs.common() % rhs.common(); }
{ {
gsl_ExpectsAudit(rhs.common().count() != quantity_values<typename QK2::rep>::zero()); gsl_ExpectsAudit(rhs.common().number() != quantity_values<typename QK2::rep>::zero());
return detail::make_quantity_kind<QK1>(lhs.common() % rhs.common()); return detail::make_quantity_kind<QK1>(lhs.common() % rhs.common());
} }

View File

@ -34,7 +34,7 @@ namespace detail {
{ {
std::vector<typename Q::rep> intervals_rep; std::vector<typename Q::rep> intervals_rep;
intervals_rep.reserve(static_cast<size_t>(std::distance(first, last))); intervals_rep.reserve(static_cast<size_t>(std::distance(first, last)));
for (auto itr = first; itr != last; ++itr) { intervals_rep.push_back(itr->count()); } for (auto itr = first; itr != last; ++itr) { intervals_rep.push_back(itr->number()); }
return intervals_rep; return intervals_rep;
} }
@ -43,7 +43,7 @@ namespace detail {
{ {
std::vector<typename Q::rep> bl_rep; std::vector<typename Q::rep> bl_rep;
bl_rep.reserve(bl.size()); bl_rep.reserve(bl.size());
for (const Q& qty : bl) { bl_rep.push_back(qty.count()); } for (const Q& qty : bl) { bl_rep.push_back(qty.number()); }
return bl_rep; return bl_rep;
} }
@ -79,7 +79,7 @@ struct uniform_int_distribution : public std::uniform_int_distribution<typename
using base = TYPENAME std::uniform_int_distribution<rep>; using base = TYPENAME std::uniform_int_distribution<rep>;
uniform_int_distribution() : base() {} uniform_int_distribution() : base() {}
uniform_int_distribution(const Q& a, const Q& b) : base(a.count(), b.count()) {} uniform_int_distribution(const Q& a, const Q& b) : base(a.number(), b.number()) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -99,7 +99,7 @@ struct uniform_real_distribution : public std::uniform_real_distribution<typenam
using base = TYPENAME std::uniform_real_distribution<rep>; using base = TYPENAME std::uniform_real_distribution<rep>;
uniform_real_distribution() : base() {} uniform_real_distribution() : base() {}
uniform_real_distribution(const Q& a, const Q& b) : base(a.count(), b.count()) {} uniform_real_distribution(const Q& a, const Q& b) : base(a.number(), b.number()) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -119,7 +119,7 @@ struct binomial_distribution : public std::binomial_distribution<typename Q::rep
using base = TYPENAME std::binomial_distribution<rep>; using base = TYPENAME std::binomial_distribution<rep>;
binomial_distribution() : base() {} binomial_distribution() : base() {}
binomial_distribution(const Q& t, double p) : base(t.count(), p) {} binomial_distribution(const Q& t, double p) : base(t.number(), p) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -138,7 +138,7 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi
using base = TYPENAME std::negative_binomial_distribution<rep>; using base = TYPENAME std::negative_binomial_distribution<rep>;
negative_binomial_distribution() : base() {} negative_binomial_distribution() : base() {}
negative_binomial_distribution(const Q& k, double p) : base(k.count(), p) {} negative_binomial_distribution(const Q& k, double p) : base(k.number(), p) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -242,7 +242,7 @@ struct extreme_value_distribution : public std::extreme_value_distribution<typen
using base = TYPENAME std::extreme_value_distribution<rep>; using base = TYPENAME std::extreme_value_distribution<rep>;
extreme_value_distribution() : base() {} extreme_value_distribution() : base() {}
extreme_value_distribution(const Q& a, const rep& b) : base(a.count(), b) {} extreme_value_distribution(const Q& a, const rep& b) : base(a.number(), b) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -261,7 +261,7 @@ struct normal_distribution : public std::normal_distribution<typename Q::rep>
using base = TYPENAME std::normal_distribution<rep>; using base = TYPENAME std::normal_distribution<rep>;
normal_distribution() : base() {} normal_distribution() : base() {}
normal_distribution(const Q& mean, const Q& stddev) : base(mean.count(), stddev.count()) {} normal_distribution(const Q& mean, const Q& stddev) : base(mean.number(), stddev.number()) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -281,7 +281,7 @@ struct lognormal_distribution : public std::lognormal_distribution<typename Q::r
using base = TYPENAME std::lognormal_distribution<rep>; using base = TYPENAME std::lognormal_distribution<rep>;
lognormal_distribution() : base() {} lognormal_distribution() : base() {}
lognormal_distribution(const Q& m, const Q& s) : base(m.count(), s.count()) {} lognormal_distribution(const Q& m, const Q& s) : base(m.number(), s.number()) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -318,7 +318,7 @@ struct cauchy_distribution : public std::cauchy_distribution<typename Q::rep>
using base = TYPENAME std::cauchy_distribution<rep>; using base = TYPENAME std::cauchy_distribution<rep>;
cauchy_distribution() : base() {} cauchy_distribution() : base() {}
cauchy_distribution(const Q& a, const Q& b) : base(a.count(), b.count()) {} cauchy_distribution(const Q& a, const Q& b) : base(a.number(), b.number()) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -416,7 +416,7 @@ public:
template <typename UnaryOperation> template <typename UnaryOperation>
piecewise_constant_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) : piecewise_constant_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) :
base(nw, xmin.count(), xmax.count(), [fw](rep val) { return fw(Q(val)); }) {} base(nw, xmin.number(), xmax.number(), [fw](rep val) { return fw(Q(val)); }) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }
@ -461,7 +461,7 @@ public:
template <typename UnaryOperation> template <typename UnaryOperation>
piecewise_linear_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) : piecewise_linear_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) :
base(nw, xmin.count(), xmax.count(), [fw](rep val) { return fw(Q(val)); }) {} base(nw, xmin.number(), xmax.number(), [fw](rep val) { return fw(Q(val)); }) {}
template<typename Generator> template<typename Generator>
Q operator()(Generator& g) { return Q(base::operator()(g)); } Q operator()(Generator& g) { return Q(base::operator()(g)); }

View File

@ -531,7 +531,7 @@ TEST_CASE("piecewise_constant_distribution")
std::initializer_list<q> intervals_qty = {1.0_q_m, 2.0_q_m, 3.0_q_m}; std::initializer_list<q> intervals_qty = {1.0_q_m, 2.0_q_m, 3.0_q_m};
auto stl_dist = std::piecewise_constant_distribution<rep>(intervals_rep, [](rep val) { return val; }); auto stl_dist = std::piecewise_constant_distribution<rep>(intervals_rep, [](rep val) { return val; });
auto units_dist = units::piecewise_constant_distribution<q>(intervals_qty, [](q qty) { return qty.count(); }); auto units_dist = units::piecewise_constant_distribution<q>(intervals_qty, [](q qty) { return qty.number(); });
CHECK(units_dist.intervals() == intervals_qty_vec); CHECK(units_dist.intervals() == intervals_qty_vec);
CHECK(units_dist.densities() == stl_dist.densities()); CHECK(units_dist.densities() == stl_dist.densities());
@ -543,7 +543,7 @@ TEST_CASE("piecewise_constant_distribution")
constexpr q xmin_qty = 1.0_q_m, xmax_qty = 3.0_q_m; constexpr q xmin_qty = 1.0_q_m, xmax_qty = 3.0_q_m;
auto stl_dist = std::piecewise_constant_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; }); auto stl_dist = std::piecewise_constant_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
auto units_dist = units::piecewise_constant_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.count(); }); auto units_dist = units::piecewise_constant_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.number(); });
CHECK(units_dist.intervals() == intervals_qty_vec); CHECK(units_dist.intervals() == intervals_qty_vec);
CHECK(units_dist.densities() == stl_dist.densities()); CHECK(units_dist.densities() == stl_dist.densities());
@ -589,7 +589,7 @@ TEST_CASE("piecewise_linear_distribution")
std::initializer_list<q> intervals_qty = {1.0_q_m, 2.0_q_m, 3.0_q_m}; std::initializer_list<q> intervals_qty = {1.0_q_m, 2.0_q_m, 3.0_q_m};
auto stl_dist = std::piecewise_linear_distribution<rep>(intervals_rep, [](rep val) { return val; }); auto stl_dist = std::piecewise_linear_distribution<rep>(intervals_rep, [](rep val) { return val; });
auto units_dist = units::piecewise_linear_distribution<q>(intervals_qty, [](q qty) { return qty.count(); }); auto units_dist = units::piecewise_linear_distribution<q>(intervals_qty, [](q qty) { return qty.number(); });
CHECK(units_dist.intervals() == intervals_qty_vec); CHECK(units_dist.intervals() == intervals_qty_vec);
CHECK(units_dist.densities() == stl_dist.densities()); CHECK(units_dist.densities() == stl_dist.densities());
@ -601,7 +601,7 @@ TEST_CASE("piecewise_linear_distribution")
constexpr q xmin_qty = 1.0_q_m, xmax_qty = 3.0_q_m; constexpr q xmin_qty = 1.0_q_m, xmax_qty = 3.0_q_m;
auto stl_dist = std::piecewise_linear_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; }); auto stl_dist = std::piecewise_linear_distribution<rep>(nw, xmin_rep, xmax_rep, [](rep val) { return val; });
auto units_dist = units::piecewise_linear_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.count(); }); auto units_dist = units::piecewise_linear_distribution<q>(nw, xmin_qty, xmax_qty, [](q qty) { return qty.number(); });
CHECK(units_dist.intervals() == intervals_qty_vec); CHECK(units_dist.intervals() == intervals_qty_vec);
CHECK(units_dist.densities() == stl_dist.densities()); CHECK(units_dist.densities() == stl_dist.densities());

View File

@ -100,13 +100,13 @@ TEST_CASE("absolute functions on quantity returns the absolute value", "[math][a
TEST_CASE("numeric_limits functions", "[limits]") TEST_CASE("numeric_limits functions", "[limits]")
{ {
SECTION ("'epsilon' works as expected using default floating type") { SECTION ("'epsilon' works as expected using default floating type") {
REQUIRE(epsilon<decltype(1._q_m)>().count() == std::numeric_limits<decltype(1._q_m)::rep>::epsilon()); REQUIRE(epsilon<decltype(1._q_m)>().number() == std::numeric_limits<decltype(1._q_m)::rep>::epsilon());
} }
SECTION ("'epsilon' works as expected using integers") { SECTION ("'epsilon' works as expected using integers") {
REQUIRE(epsilon<decltype(1_q_m)>().count() == std::numeric_limits<decltype(1_q_m)::rep>::epsilon()); REQUIRE(epsilon<decltype(1_q_m)>().number() == std::numeric_limits<decltype(1_q_m)::rep>::epsilon());
} }
SECTION ("'epsilon' works as expected using mixed Rep types") { SECTION ("'epsilon' works as expected using mixed Rep types") {
REQUIRE(epsilon<decltype(1_q_m)>().count() != std::numeric_limits<decltype(1._q_m)::rep>::epsilon()); REQUIRE(epsilon<decltype(1_q_m)>().number() != std::numeric_limits<decltype(1._q_m)::rep>::epsilon());
} }
} }

View File

@ -51,8 +51,8 @@ static_assert(centimetre::symbol == "cm");
// speed // speed
static_assert((10_q_cm / 5_q_s).count() == 2); static_assert((10_q_cm / 5_q_s).number() == 2);
static_assert((2_q_cm_per_s).count() == 2); static_assert((2_q_cm_per_s).number() == 2);
static_assert(10_q_cm / 5_q_s == 2_q_cm_per_s); static_assert(10_q_cm / 5_q_s == 2_q_cm_per_s);
static_assert(10_q_cm / 2_q_cm_per_s == 5_q_s); static_assert(10_q_cm / 2_q_cm_per_s == 5_q_s);
static_assert(10_q_cm == 2_q_cm_per_s * 5_q_s); static_assert(10_q_cm == 2_q_cm_per_s * 5_q_s);
@ -62,8 +62,8 @@ static_assert(detail::unit_text<dim_speed, centimetre_per_second>() == "cm/s");
// area // area
static_assert(centimetre::ratio / dimension_unit<dim_length>::ratio == ratio(1)); static_assert(centimetre::ratio / dimension_unit<dim_length>::ratio == ratio(1));
static_assert((1_q_cm * 1_q_cm).count() == 1); static_assert((1_q_cm * 1_q_cm).number() == 1);
static_assert((1_q_cm2).count() == 1); static_assert((1_q_cm2).number() == 1);
static_assert(1_q_cm * 1_q_cm == 1_q_cm2); static_assert(1_q_cm * 1_q_cm == 1_q_cm2);
static_assert(100_q_cm * 100_q_cm == area<isq::si::square_metre>(1)); static_assert(100_q_cm * 100_q_cm == area<isq::si::square_metre>(1));
static_assert(100_q_cm * 100_q_cm == length<isq::si::metre>(1) * length<isq::si::metre>(1)); static_assert(100_q_cm * 100_q_cm == length<isq::si::metre>(1) * length<isq::si::metre>(1));

View File

@ -167,8 +167,8 @@ static_assert(width<metre, double>::zero().common() == 0 * m);
static_assert(width<metre, double>::one().common() == 1 * m); static_assert(width<metre, double>::one().common() == 1 * m);
static_assert(width<metre, unsigned>::min().common() == 0 * m); static_assert(width<metre, unsigned>::min().common() == 0 * m);
static_assert(width<metre, unsigned>::max().common() == std::numeric_limits<unsigned>::max() * m); static_assert(width<metre, unsigned>::max().common() == std::numeric_limits<unsigned>::max() * m);
static_assert(width<metre, double>::min().common().count() == std::numeric_limits<double>::lowest()); static_assert(width<metre, double>::min().common().number() == std::numeric_limits<double>::lowest());
static_assert(width<metre, double>::max().common().count() == std::numeric_limits<double>::max()); static_assert(width<metre, double>::max().common().number() == std::numeric_limits<double>::max());
//////////////////////// ////////////////////////
@ -204,8 +204,8 @@ static_assert(same(quantity_kind(rate_of_climb<kilometre_per_hour, double>(0.01
static_assert(construct_from_only<apples<one, int>>(1).common() == 1); static_assert(construct_from_only<apples<one, int>>(1).common() == 1);
static_assert(construct_from_only<apples<one, double>>(1.0).common() == 1); static_assert(construct_from_only<apples<one, double>>(1.0).common() == 1);
static_assert(construct_from_only<apples<percent, int>>(1ULL).common().count() == 1); static_assert(construct_from_only<apples<percent, int>>(1ULL).common().number() == 1);
static_assert(construct_from_only<apples<percent, double>>(1.0L).common().count() == 1); static_assert(construct_from_only<apples<percent, double>>(1.0L).common().number() == 1);
static_assert(!constructible_or_convertible_from<apples<one, int>>(1.0)); static_assert(!constructible_or_convertible_from<apples<one, int>>(1.0));
static_assert(!constructible_or_convertible_from<apples<percent, int>>(1.0)); static_assert(!constructible_or_convertible_from<apples<percent, int>>(1.0));
static_assert(!constructible_or_convertible_from<width<metre, double>>(1.0)); static_assert(!constructible_or_convertible_from<width<metre, double>>(1.0));
@ -248,20 +248,20 @@ static_assert(construct_from_only<width<metre, short>>(1 * m).common() == 1 * m)
static_assert(construct_from_only<apples<one, int>>(quantity(1)).common() == 1); static_assert(construct_from_only<apples<one, int>>(quantity(1)).common() == 1);
static_assert(construct_from_only<apples<one, double>>(dimensionless<percent>(1)).common() == 0.01); static_assert(construct_from_only<apples<one, double>>(dimensionless<percent>(1)).common() == 0.01);
static_assert(construct_from_only<apples<percent, double>>(quantity(1.0)).common().count() == 100); static_assert(construct_from_only<apples<percent, double>>(quantity(1.0)).common().number() == 100);
static_assert(construct_from_only<apples<percent, double>>(dimensionless<percent>(1)).common().count() == 1); static_assert(construct_from_only<apples<percent, double>>(dimensionless<percent>(1)).common().number() == 1);
static_assert(construct_from_only<apples<one, double>>(quantity(1.0)).common() == 1); static_assert(construct_from_only<apples<one, double>>(quantity(1.0)).common() == 1);
static_assert(construct_from_only<apples<one, double>>(quantity(1.0f)).common() == 1); static_assert(construct_from_only<apples<one, double>>(quantity(1.0f)).common() == 1);
static_assert(construct_from_only<apples<one, float>>(quantity(1.0)).common() == 1); static_assert(construct_from_only<apples<one, float>>(quantity(1.0)).common() == 1);
static_assert(construct_from_only<apples<one, double>>(quantity(1)).common() == 1); static_assert(construct_from_only<apples<one, double>>(quantity(1)).common() == 1);
static_assert(construct_from_only<apples<one, double>>(quantity(short{1})).common() == 1); static_assert(construct_from_only<apples<one, double>>(quantity(short{1})).common() == 1);
static_assert(construct_from_only<apples<one, short>>(quantity(1)).common() == 1); static_assert(construct_from_only<apples<one, short>>(quantity(1)).common() == 1);
static_assert(construct_from_only<apples<percent, double>>(quantity(1.0)).common().count() == 1e2); static_assert(construct_from_only<apples<percent, double>>(quantity(1.0)).common().number() == 1e2);
static_assert(construct_from_only<apples<percent, double>>(quantity(1.0f)).common().count() == 1e2); static_assert(construct_from_only<apples<percent, double>>(quantity(1.0f)).common().number() == 1e2);
static_assert(construct_from_only<apples<percent, float>>(quantity(1.0)).common().count() == 1e2f); static_assert(construct_from_only<apples<percent, float>>(quantity(1.0)).common().number() == 1e2f);
static_assert(construct_from_only<apples<percent, double>>(quantity(1)).common().count() == 1e2); static_assert(construct_from_only<apples<percent, double>>(quantity(1)).common().number() == 1e2);
static_assert(construct_from_only<apples<percent, double>>(quantity(short{1})).common().count() == 1e2); static_assert(construct_from_only<apples<percent, double>>(quantity(short{1})).common().number() == 1e2);
static_assert(construct_from_only<apples<percent, short>>(quantity(1)).common().count() == 1e2); static_assert(construct_from_only<apples<percent, short>>(quantity(1)).common().number() == 1e2);
static_assert(!constructible_or_convertible_from<dimensionless<one, double>>(apples<one, double>{})); static_assert(!constructible_or_convertible_from<dimensionless<one, double>>(apples<one, double>{}));
static_assert(!constructible_or_convertible_from<dimensionless<one, double>>(apples<one, float>{})); static_assert(!constructible_or_convertible_from<dimensionless<one, double>>(apples<one, float>{}));
@ -471,12 +471,12 @@ static_assert(same(width<metre, double>(2. * m) - width<metre, int>(3 * m), widt
static_assert(same(width<metre, double>(2e3 * m) - width<kilometre, int>(3 * km), width<metre, double>(-1e3 * m))); static_assert(same(width<metre, double>(2e3 * m) - width<kilometre, int>(3 * km), width<metre, double>(-1e3 * m)));
static_assert(is_same_v< static_assert(is_same_v<
decltype((width<metre, std::uint8_t>(0 * m) + width<metre, std::uint8_t>(0 * m)).common().count()), int>); decltype((width<metre, std::uint8_t>(0 * m) + width<metre, std::uint8_t>(0 * m)).common().number()), int>);
static_assert(is_same_v< static_assert(is_same_v<
decltype((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(0 * m)).common().count()), int>); decltype((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(0 * m)).common().number()), int>);
static_assert((width<metre, std::uint8_t>(128 * m) + width<metre, std::uint8_t>(128 * m)).common().count() == static_assert((width<metre, std::uint8_t>(128 * m) + width<metre, std::uint8_t>(128 * m)).common().number() ==
std::uint8_t(128) + std::uint8_t(128)); std::uint8_t(128) + std::uint8_t(128));
static_assert((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(1 * m)).common().count() == static_assert((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(1 * m)).common().number() ==
std::uint8_t(0) - std::uint8_t(1)); std::uint8_t(0) - std::uint8_t(1));
static_assert(!std::is_invocable_v<std::plus<>, width<metre>, double>); static_assert(!std::is_invocable_v<std::plus<>, width<metre>, double>);
@ -641,7 +641,7 @@ static_assert(same(width<metre, int>(2 * m) % 3, width<metre, int>(2 * m)));
static_assert(same(width<metre, int>(3 * m) % width<metre, int>(2 * m), width<metre, int>(1 * m))); static_assert(same(width<metre, int>(3 * m) % width<metre, int>(2 * m), width<metre, int>(1 * m)));
static_assert(is_same_v< static_assert(is_same_v<
decltype((width<metre, std::uint8_t>(0 * m) % width<metre, std::uint8_t>(0 * m)).common().count()), decltype((width<metre, std::uint8_t>(0 * m) % width<metre, std::uint8_t>(0 * m)).common().number()),
decltype(std::uint8_t(0) % std::uint8_t(0))>); decltype(std::uint8_t(0) % std::uint8_t(0))>);
static_assert(!std::is_invocable_v<std::multiplies<>, reference<dim_length, metre>, width<metre>>); static_assert(!std::is_invocable_v<std::multiplies<>, reference<dim_length, metre>, width<metre>>);

View File

@ -179,8 +179,8 @@ static_assert(same(abscissa<metre>{}.relative(), width<metre>{}));
static_assert(abscissa<metre, unsigned>::min().relative().common() == 0 * m); static_assert(abscissa<metre, unsigned>::min().relative().common() == 0 * m);
static_assert(abscissa<metre, unsigned>::max().relative().common() == std::numeric_limits<unsigned>::max() * m); static_assert(abscissa<metre, unsigned>::max().relative().common() == std::numeric_limits<unsigned>::max() * m);
static_assert(abscissa<metre, double>::min().relative().common().count() == std::numeric_limits<double>::lowest()); static_assert(abscissa<metre, double>::min().relative().common().number() == std::numeric_limits<double>::lowest());
static_assert(abscissa<metre, double>::max().relative().common().count() == std::numeric_limits<double>::max()); static_assert(abscissa<metre, double>::max().relative().common().number() == std::numeric_limits<double>::max());
//////////////////////// ////////////////////////
@ -220,8 +220,8 @@ static_assert(construct_from_only<nth_apple<one, double>>(1).relative().common()
static_assert(construct_from_only<nth_apple<one, double>>(short{1}).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, double>>(short{1}).relative().common() == 1);
static_assert(construct_from_only<nth_apple<one, short>>(1).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, short>>(1).relative().common() == 1);
static_assert(construct_from_only<nth_apple<one, int>>(1).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, int>>(1).relative().common() == 1);
static_assert(construct_from_only<nth_apple<percent, int>>(1ULL).relative().common().count() == 1); static_assert(construct_from_only<nth_apple<percent, int>>(1ULL).relative().common().number() == 1);
static_assert(construct_from_only<nth_apple<percent, double>>(1).relative().common().count() == 1); static_assert(construct_from_only<nth_apple<percent, double>>(1).relative().common().number() == 1);
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(1.0)); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(1.0));
static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(1.0)); static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(1.0));
static_assert(!constructible_or_convertible_from<abscissa<metre, double>>(1.0)); static_assert(!constructible_or_convertible_from<abscissa<metre, double>>(1.0));
@ -256,8 +256,8 @@ static_assert(!constructible_or_convertible_from<abscissa<metre, int>>(1s));
static_assert(construct_from_only<nth_apple<one, int>>(quantity(1)).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, int>>(quantity(1)).relative().common() == 1);
static_assert(construct_from_only<nth_apple<one, double>>(dimensionless<percent>(1)).relative().common() == 0.01); static_assert(construct_from_only<nth_apple<one, double>>(dimensionless<percent>(1)).relative().common() == 0.01);
static_assert(construct_from_only<nth_apple<one, double>>(dimensionless<percent>(1)).relative().common() == 0.01); static_assert(construct_from_only<nth_apple<one, double>>(dimensionless<percent>(1)).relative().common() == 0.01);
static_assert(construct_from_only<nth_apple<percent, double>>(dimensionless<percent>(1)).relative().common().count() == 1); static_assert(construct_from_only<nth_apple<percent, double>>(dimensionless<percent>(1)).relative().common().number() == 1);
static_assert(construct_from_only<nth_apple<percent, double>>(quantity(1)).relative().common().count() == 100); static_assert(construct_from_only<nth_apple<percent, double>>(quantity(1)).relative().common().number() == 100);
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity(1.0)));
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(dimensionless<percent>(1))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(dimensionless<percent>(1)));
static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(quantity(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(quantity(1.0)));
@ -293,8 +293,8 @@ static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(1)).rel
static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(dimensionless<percent, int>(1))).relative().common() == 0.01); static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(dimensionless<percent, int>(1))).relative().common() == 0.01);
static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(1.0)).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(1.0)).relative().common() == 1);
static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(dimensionless<percent, double>(1.0))).relative().common() == 0.01); static_assert(construct_from_only<nth_apple<one, double>>(quantity_point(dimensionless<percent, double>(1.0))).relative().common() == 0.01);
static_assert(construct_from_only<nth_apple<percent, int>>(quantity_point(1)).relative().common().count() == 100); static_assert(construct_from_only<nth_apple<percent, int>>(quantity_point(1)).relative().common().number() == 100);
static_assert(construct_from_only<nth_apple<percent, double>>(quantity_point(dimensionless<percent>(1))).relative().common().count() == 1); static_assert(construct_from_only<nth_apple<percent, double>>(quantity_point(dimensionless<percent>(1))).relative().common().number() == 1);
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity_point(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity_point(1.0)));
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity_point(dimensionless<percent>(1)))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(quantity_point(dimensionless<percent>(1))));
static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(quantity_point(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(quantity_point(1.0)));
@ -327,8 +327,8 @@ static_assert(!constructible_or_convertible_from<abscissa<metre, int>>(abscissa_
static_assert(construct_from_only<nth_apple<one, int>>(apples<one, int>(1)).relative().common() == 1); static_assert(construct_from_only<nth_apple<one, int>>(apples<one, int>(1)).relative().common() == 1);
static_assert(construct_from_only<nth_apple<one, double>>(apples<percent, double>(dimensionless<percent>(1))).relative().common() == 0.01); static_assert(construct_from_only<nth_apple<one, double>>(apples<percent, double>(dimensionless<percent>(1))).relative().common() == 0.01);
static_assert(construct_from_only<nth_apple<percent, int>>(apples<one, int>(1)).relative().common().count() == 100); static_assert(construct_from_only<nth_apple<percent, int>>(apples<one, int>(1)).relative().common().number() == 100);
static_assert(construct_from_only<nth_apple<percent, double>>(apples<percent, double>(dimensionless<percent>(1))).relative().common().count() == 1); static_assert(construct_from_only<nth_apple<percent, double>>(apples<percent, double>(dimensionless<percent>(1))).relative().common().number() == 1);
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(apples<one, double>(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(apples<one, double>(1.0)));
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(apples<percent, double>(dimensionless<percent>(1)))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(apples<percent, double>(dimensionless<percent>(1))));
static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(apples<one, double>(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(apples<one, double>(1.0)));
@ -354,8 +354,8 @@ static_assert(!constructible_or_convertible_from<abscissa<metre, int>>(quantity_
static_assert(construct_and_convert_from<nth_apple<one, int>>(nth_apple<one, int>(1)).relative().common() == 1); static_assert(construct_and_convert_from<nth_apple<one, int>>(nth_apple<one, int>(1)).relative().common() == 1);
static_assert(construct_and_convert_from<nth_apple<one, double>>(nth_apple<percent, double>(dimensionless<percent>(1))).relative().common() == 0.01); static_assert(construct_and_convert_from<nth_apple<one, double>>(nth_apple<percent, double>(dimensionless<percent>(1))).relative().common() == 0.01);
static_assert(construct_and_convert_from<nth_apple<percent, int>>(nth_apple<one, int>(1)).relative().common().count() == 100); static_assert(construct_and_convert_from<nth_apple<percent, int>>(nth_apple<one, int>(1)).relative().common().number() == 100);
static_assert(construct_and_convert_from<nth_apple<percent, double>>(nth_apple<percent, double>(dimensionless<percent>(1))).relative().common().count() == 1); static_assert(construct_and_convert_from<nth_apple<percent, double>>(nth_apple<percent, double>(dimensionless<percent>(1))).relative().common().number() == 1);
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(nth_apple<one, double>(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(nth_apple<one, double>(1.0)));
static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(nth_apple<percent, double>(dimensionless<percent>(1)))); static_assert(!constructible_or_convertible_from<nth_apple<percent, int>>(nth_apple<percent, double>(dimensionless<percent>(1))));
static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(nth_apple<one, double>(1.0))); static_assert(!constructible_or_convertible_from<nth_apple<one, int>>(nth_apple<one, double>(1.0)));

View File

@ -99,11 +99,11 @@ static_assert([]() { quantity_point<dim_length, metre, int> l1(1_q_m), l2{}; ret
// static member functions // static member functions
static_assert(quantity_point<dim_length, metre, int>::min().relative().count() == std::numeric_limits<int>::lowest()); static_assert(quantity_point<dim_length, metre, int>::min().relative().number() == std::numeric_limits<int>::lowest());
static_assert(quantity_point<dim_length, metre, int>::max().relative().count() == std::numeric_limits<int>::max()); static_assert(quantity_point<dim_length, metre, int>::max().relative().number() == std::numeric_limits<int>::max());
static_assert(quantity_point<dim_length, metre, double>::min().relative().count() == static_assert(quantity_point<dim_length, metre, double>::min().relative().number() ==
std::numeric_limits<double>::lowest()); std::numeric_limits<double>::lowest());
static_assert(quantity_point<dim_length, metre, double>::max().relative().count() == static_assert(quantity_point<dim_length, metre, double>::max().relative().number() ==
std::numeric_limits<double>::max()); std::numeric_limits<double>::max());
// unary member operators // unary member operators
@ -127,8 +127,8 @@ static_assert([](auto v) {
// compound assignment // compound assignment
static_assert((quantity_point(1_q_m) += 1_q_m).relative().count() == 2); static_assert((quantity_point(1_q_m) += 1_q_m).relative().number() == 2);
static_assert((quantity_point(2_q_m) -= 1_q_m).relative().count() == 1); static_assert((quantity_point(2_q_m) -= 1_q_m).relative().number() == 1);
// non-member arithmetic operators // non-member arithmetic operators
@ -151,10 +151,10 @@ static_assert(
compare<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()), compare<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()),
length<metre, double>>); length<metre, double>>);
static_assert((1_q_m + km).relative().count() == 1001); static_assert((1_q_m + km).relative().number() == 1001);
static_assert((quantity_point(1_q_m) + 1_q_km).relative().count() == 1001); static_assert((quantity_point(1_q_m) + 1_q_km).relative().number() == 1001);
static_assert((km - 1_q_m).relative().count() == 999); static_assert((km - 1_q_m).relative().number() == 999);
static_assert((quantity_point(1_q_km) - quantity_point(1_q_m)).count() == 999); static_assert((quantity_point(1_q_km) - quantity_point(1_q_m)).number() == 999);
// comparators // comparators
@ -221,19 +221,19 @@ static_assert(std::equality_comparable_with<decltype(quantity_point(1_q_m)), dec
// quantity_cast // quantity_cast
static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(2_q_km)).relative().count() == static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(2_q_km)).relative().number() ==
2000); 2000);
static_assert( static_assert(
quantity_point_cast<quantity_point<dim_length, kilometre, int>>(quantity_point(2000_q_m)).relative().count() == 2); quantity_point_cast<quantity_point<dim_length, kilometre, int>>(quantity_point(2000_q_m)).relative().number() == 2);
static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(1.23_q_m)).relative().count() == static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(1.23_q_m)).relative().number() ==
1); 1);
static_assert(quantity_point_cast<length<metre, int>>(quantity_point(2_q_km)).relative().count() == 2000); static_assert(quantity_point_cast<length<metre, int>>(quantity_point(2_q_km)).relative().number() == 2000);
static_assert(quantity_point_cast<length<kilometre, int>>(quantity_point(2000_q_m)).relative().count() == 2); static_assert(quantity_point_cast<length<kilometre, int>>(quantity_point(2000_q_m)).relative().number() == 2);
static_assert(quantity_point_cast<length<metre, int>>(quantity_point(1.23_q_m)).relative().count() == 1); static_assert(quantity_point_cast<length<metre, int>>(quantity_point(1.23_q_m)).relative().number() == 1);
static_assert(quantity_point_cast<metre>(quantity_point(2_q_km)).relative().count() == 2000); static_assert(quantity_point_cast<metre>(quantity_point(2_q_km)).relative().number() == 2000);
static_assert(quantity_point_cast<kilometre>(quantity_point(2000_q_m)).relative().count() == 2); static_assert(quantity_point_cast<kilometre>(quantity_point(2000_q_m)).relative().number() == 2);
static_assert(quantity_point_cast<int>(quantity_point(1.23_q_m)).relative().count() == 1); static_assert(quantity_point_cast<int>(quantity_point(1.23_q_m)).relative().number() == 1);
static_assert(quantity_point_cast<dim_speed, kilometre_per_hour>(quantity_point(2000.0_q_m / 3600.0_q_s)).relative().count() == 2); static_assert(quantity_point_cast<dim_speed, kilometre_per_hour>(quantity_point(2000.0_q_m / 3600.0_q_s)).relative().number() == 2);
// time // time

View File

@ -106,12 +106,12 @@ static_assert(is_same_v<fps::length<fps::mile>::rep, double>);
// static member functions // static member functions
//////////////////////////// ////////////////////////////
static_assert(length<metre, int>::zero().count() == 0); static_assert(length<metre, int>::zero().number() == 0);
static_assert(length<metre, int>::min().count() == std::numeric_limits<int>::lowest()); static_assert(length<metre, int>::min().number() == std::numeric_limits<int>::lowest());
static_assert(length<metre, int>::max().count() == std::numeric_limits<int>::max()); static_assert(length<metre, int>::max().number() == std::numeric_limits<int>::max());
static_assert(length<metre, double>::zero().count() == 0.0); static_assert(length<metre, double>::zero().number() == 0.0);
static_assert(length<metre, double>::min().count() == std::numeric_limits<double>::lowest()); static_assert(length<metre, double>::min().number() == std::numeric_limits<double>::lowest());
static_assert(length<metre, double>::max().count() == std::numeric_limits<double>::max()); static_assert(length<metre, double>::max().number() == std::numeric_limits<double>::max());
////////////////////////////// //////////////////////////////
@ -182,11 +182,11 @@ static_assert(!std::convertible_to<double, length<metre, int>>);
static_assert(!std::constructible_from<dimensionless<one, int>, double>); static_assert(!std::constructible_from<dimensionless<one, int>, double>);
static_assert(!std::convertible_to<double, dimensionless<one, int>>); static_assert(!std::convertible_to<double, dimensionless<one, int>>);
static_assert(length<metre, int>().count() == 0); // value initialization static_assert(length<metre, int>().number() == 0); // value initialization
static_assert(length<metre, int>(1).count() == 1); static_assert(length<metre, int>(1).number() == 1);
static_assert(length<metre, double>(1.0).count() == 1.0); static_assert(length<metre, double>(1.0).number() == 1.0);
static_assert(length<metre, double>(1).count() == 1.0); static_assert(length<metre, double>(1).number() == 1.0);
static_assert(length<metre, double>(3.14).count() == 3.14); static_assert(length<metre, double>(3.14).number() == 3.14);
/////////////////////////////////////// ///////////////////////////////////////
@ -226,10 +226,10 @@ static_assert(std::convertible_to<length<kilometre, int>, length<metre>>);
static_assert(std::constructible_from<length<kilometre>, length<metre, int>>); static_assert(std::constructible_from<length<kilometre>, length<metre, int>>);
static_assert(std::convertible_to<length<metre, int>, length<kilometre>>); static_assert(std::convertible_to<length<metre, int>, length<kilometre>>);
static_assert(length<metre, int>(123_q_m).count() == 123); static_assert(length<metre, int>(123_q_m).number() == 123);
static_assert(length<kilometre, int>(2_q_km).count() == 2); static_assert(length<kilometre, int>(2_q_km).number() == 2);
static_assert(length<metre, int>(2_q_km).count() == 2000); static_assert(length<metre, int>(2_q_km).number() == 2000);
static_assert(length<kilometre>(1500_q_m).count() == 1.5); static_assert(length<kilometre>(1500_q_m).number() == 1.5);
///////// /////////
@ -248,25 +248,25 @@ static_assert(is_same_v<decltype(quantity{1.23}), dimensionless<one, double>>);
// assignment operator // assignment operator
//////////////////////// ////////////////////////
static_assert([]() { length<metre, int> l1(1), l2(2); return l2 = l1; }().count() == 1); static_assert([]() { length<metre, int> l1(1), l2(2); return l2 = l1; }().number() == 1);
static_assert([]() { length<metre, int> l1(1), l2(2); return l2 = std::move(l1); }().count() == 1); static_assert([]() { length<metre, int> l1(1), l2(2); return l2 = std::move(l1); }().number() == 1);
//////////////////// ////////////////////
// unary operators // unary operators
//////////////////// ////////////////////
static_assert((+123_q_m).count() == 123); static_assert((+123_q_m).number() == 123);
static_assert((-123_q_m).count() == -123); static_assert((-123_q_m).number() == -123);
static_assert((+(-123_q_m)).count() == -123); static_assert((+(-123_q_m)).number() == -123);
static_assert((-(-123_q_m)).count() == 123); static_assert((-(-123_q_m)).number() == 123);
static_assert([](auto v) { auto vv = v++; return std::pair(v, vv); }(123_q_m) == std::pair(124_q_m, 123_q_m)); static_assert([](auto v) { auto vv = v++; return std::pair(v, vv); }(123_q_m) == std::pair(124_q_m, 123_q_m));
static_assert([](auto v) { auto vv = ++v; return std::pair(v, vv); }(123_q_m) == std::pair(124_q_m, 124_q_m)); static_assert([](auto v) { auto vv = ++v; return std::pair(v, vv); }(123_q_m) == std::pair(124_q_m, 124_q_m));
static_assert([](auto v) { auto vv = v--; return std::pair(v, vv); }(123_q_m) == std::pair(122_q_m, 123_q_m)); static_assert([](auto v) { auto vv = v--; return std::pair(v, vv); }(123_q_m) == std::pair(122_q_m, 123_q_m));
static_assert([](auto v) { auto vv = --v; return std::pair(v, vv); }(123_q_m) == std::pair(122_q_m, 122_q_m)); static_assert([](auto v) { auto vv = --v; return std::pair(v, vv); }(123_q_m) == std::pair(122_q_m, 122_q_m));
static_assert(is_same_v<decltype((+(short{0} * m)).count()), int>); static_assert(is_same_v<decltype((+(short{0} * m)).number()), int>);
//////////////////////// ////////////////////////
@ -274,42 +274,42 @@ static_assert(is_same_v<decltype((+(short{0} * m)).count()), int>);
//////////////////////// ////////////////////////
// same type // same type
static_assert((1_q_m += 1_q_m).count() == 2); static_assert((1_q_m += 1_q_m).number() == 2);
static_assert((2_q_m -= 1_q_m).count() == 1); static_assert((2_q_m -= 1_q_m).number() == 1);
static_assert((1_q_m *= 2).count() == 2); static_assert((1_q_m *= 2).number() == 2);
static_assert((2_q_m /= 2).count() == 1); static_assert((2_q_m /= 2).number() == 1);
static_assert((7_q_m %= 2).count() == 1); static_assert((7_q_m %= 2).number() == 1);
static_assert((1_q_m *= quantity(2)).count() == 2); static_assert((1_q_m *= quantity(2)).number() == 2);
static_assert((2_q_m /= quantity(2)).count() == 1); static_assert((2_q_m /= quantity(2)).number() == 1);
static_assert((7_q_m %= quantity(2)).count() == 1); static_assert((7_q_m %= quantity(2)).number() == 1);
static_assert((7_q_m %= 2_q_m).count() == 1); static_assert((7_q_m %= 2_q_m).number() == 1);
// different types // different types
static_assert((2.5_q_m += 3_q_m).count() == 5.5); static_assert((2.5_q_m += 3_q_m).number() == 5.5);
static_assert((123_q_m += 1_q_km).count() == 1123); static_assert((123_q_m += 1_q_km).number() == 1123);
static_assert((5.5_q_m -= 3_q_m).count() == 2.5); static_assert((5.5_q_m -= 3_q_m).number() == 2.5);
static_assert((1123_q_m -= 1_q_km).count() == 123); static_assert((1123_q_m -= 1_q_km).number() == 123);
static_assert((2.5_q_m *= 3).count() == 7.5); static_assert((2.5_q_m *= 3).number() == 7.5);
static_assert((7.5_q_m /= 3).count() == 2.5); static_assert((7.5_q_m /= 3).number() == 2.5);
static_assert((2.5_q_m *= quantity(3)).count() == 7.5); static_assert((2.5_q_m *= quantity(3)).number() == 7.5);
static_assert((7.5_q_m /= quantity(3)).count() == 2.5); static_assert((7.5_q_m /= quantity(3)).number() == 2.5);
static_assert((3500_q_m %= 1_q_km).count() == 500); static_assert((3500_q_m %= 1_q_km).number() == 500);
static_assert((std::uint8_t(255) * m %= 256).count() == [] { std::uint8_t ui(255); return ui %= 256; }()); static_assert((std::uint8_t(255) * m %= 256).number() == [] { std::uint8_t ui(255); return ui %= 256; }());
static_assert((std::uint8_t(255) * m %= quantity(256)).count() == [] { std::uint8_t ui(255); return ui %= 256; }()); static_assert((std::uint8_t(255) * m %= quantity(256)).number() == [] { std::uint8_t ui(255); return ui %= 256; }());
// static_assert((std::uint8_t(255) * m %= 256 * m).count() != [] { std::uint8_t ui(255); return ui %= 256; }()); // UB // static_assert((std::uint8_t(255) * m %= 256 * m).number() != [] { std::uint8_t ui(255); return ui %= 256; }()); // UB
static_assert((std::uint8_t(255) * m %= 257).count() == [] { std::uint8_t ui(255); return ui %= 257; }()); static_assert((std::uint8_t(255) * m %= 257).number() == [] { std::uint8_t ui(255); return ui %= 257; }());
static_assert((std::uint8_t(255) * m %= quantity(257)).count() == [] { std::uint8_t ui(255); return ui %= 257; }()); static_assert((std::uint8_t(255) * m %= quantity(257)).number() == [] { std::uint8_t ui(255); return ui %= 257; }());
// TODO: Fix // TODO: Fix
static_assert((std::uint8_t(255) * m %= 257 * m).count() != [] { std::uint8_t ui(255); return ui %= 257; }()); static_assert((std::uint8_t(255) * m %= 257 * m).number() != [] { std::uint8_t ui(255); return ui %= 257; }());
#ifndef UNITS_COMP_MSVC // TODO ICE (https://developercommunity2.visualstudio.com/t/ICE-on-a-constexpr-operator-in-mp-unit/1302907) #ifndef UNITS_COMP_MSVC // TODO ICE (https://developercommunity2.visualstudio.com/t/ICE-on-a-constexpr-operator-in-mp-unit/1302907)
// next two lines trigger conversions warnings // next two lines trigger conversions warnings
// (warning disabled in CMake for this file) // (warning disabled in CMake for this file)
static_assert((22_q_m *= 33.33).count() == 733); static_assert((22_q_m *= 33.33).number() == 733);
static_assert((22_q_m /= 3.33).count() == 6); static_assert((22_q_m /= 3.33).number() == 6);
static_assert((22_q_m *= quantity(33.33)).count() == 733); static_assert((22_q_m *= quantity(33.33)).number() == 733);
static_assert((22_q_m /= quantity(3.33)).count() == 6); static_assert((22_q_m /= quantity(3.33)).number() == 6);
#endif #endif
template<typename Metre, typename Kilometre> template<typename Metre, typename Kilometre>
@ -403,12 +403,12 @@ static_assert(compare<decltype(1 / 1_q_s), frequency<hertz, std::int64_t>>);
static_assert(compare<decltype(quantity{1} / 1_q_s), frequency<hertz, std::int64_t>>); static_assert(compare<decltype(quantity{1} / 1_q_s), frequency<hertz, std::int64_t>>);
static_assert(compare<decltype(dimensionless<percent, std::int64_t>(1) / 1_q_s), frequency<scaled_unit<ratio(1, 100), hertz>, std::int64_t>>); static_assert(compare<decltype(dimensionless<percent, std::int64_t>(1) / 1_q_s), frequency<scaled_unit<ratio(1, 100), hertz>, std::int64_t>>);
static_assert(is_same_v<decltype((std::uint8_t(0) * m + std::uint8_t(0) * m).count()), int>); static_assert(is_same_v<decltype((std::uint8_t(0) * m + std::uint8_t(0) * m).number()), int>);
static_assert(is_same_v<decltype((std::uint8_t(0) * m - std::uint8_t(0) * m).count()), int>); static_assert(is_same_v<decltype((std::uint8_t(0) * m - std::uint8_t(0) * m).number()), int>);
static_assert((std::uint8_t(128) * m + std::uint8_t(128) * m).count() == std::uint8_t(128) + std::uint8_t(128)); static_assert((std::uint8_t(128) * m + std::uint8_t(128) * m).number() == std::uint8_t(128) + std::uint8_t(128));
static_assert((std::uint8_t(0) * m - std::uint8_t(1) * m).count() == std::uint8_t(0) - std::uint8_t(1)); static_assert((std::uint8_t(0) * m - std::uint8_t(1) * m).number() == std::uint8_t(0) - std::uint8_t(1));
static_assert(is_same_v<decltype(((std::uint8_t(0) * m) % (std::uint8_t(0) * m)).count()), static_assert(is_same_v<decltype(((std::uint8_t(0) * m) % (std::uint8_t(0) * m)).number()),
decltype(std::uint8_t(0) % std::uint8_t(0))>); decltype(std::uint8_t(0) % std::uint8_t(0))>);
// different representation types // different representation types
@ -487,75 +487,75 @@ static_assert(compare<decltype(1_q_m / 1_q_s), speed<metre_per_second, std::int6
static_assert(compare<decltype(1_q_m / 1_q_min), speed<scaled_unit<ratio(1, 60), metre_per_second>, std::int64_t>>); static_assert(compare<decltype(1_q_m / 1_q_min), speed<scaled_unit<ratio(1, 60), metre_per_second>, std::int64_t>>);
static_assert(compare<decltype(1_q_min / 1_q_m), quantity<unknown_dimension<exponent<dim_length, -1>, exponent<dim_time, 1>>, scaled_unit<ratio(60), unknown_coherent_unit>, std::int64_t>>); static_assert(compare<decltype(1_q_min / 1_q_m), quantity<unknown_dimension<exponent<dim_length, -1>, exponent<dim_time, 1>>, scaled_unit<ratio(60), unknown_coherent_unit>, std::int64_t>>);
static_assert((1_q_m + 1_q_m).count() == 2); static_assert((1_q_m + 1_q_m).number() == 2);
static_assert((1_q_m + 1_q_km).count() == 1001); static_assert((1_q_m + 1_q_km).number() == 1001);
static_assert((1_q_km + 1_q_m).count() == 1001); static_assert((1_q_km + 1_q_m).number() == 1001);
static_assert((2_q_m - 1_q_m).count() == 1); static_assert((2_q_m - 1_q_m).number() == 1);
static_assert((1_q_km - 1_q_m).count() == 999); static_assert((1_q_km - 1_q_m).number() == 999);
static_assert((2_q_m * 2).count() == 4); static_assert((2_q_m * 2).number() == 4);
static_assert((2_q_m * quantity{2}).count() == 4); static_assert((2_q_m * quantity{2}).number() == 4);
static_assert((2_q_m * dimensionless<percent, int>(2)).count() == 4); static_assert((2_q_m * dimensionless<percent, int>(2)).number() == 4);
static_assert((3 * 3_q_m).count() == 9); static_assert((3 * 3_q_m).number() == 9);
static_assert((quantity{3} * 3_q_m).count() == 9); static_assert((quantity{3} * 3_q_m).number() == 9);
static_assert((dimensionless<percent, int>(3) * 3_q_m).count() == 9); static_assert((dimensionless<percent, int>(3) * 3_q_m).number() == 9);
static_assert((4_q_m / 2).count() == 2); static_assert((4_q_m / 2).number() == 2);
static_assert((4_q_m / quantity{2}).count() == 2); static_assert((4_q_m / quantity{2}).number() == 2);
static_assert((4_q_m / dimensionless<percent, int>(2)).count() == 2); static_assert((4_q_m / dimensionless<percent, int>(2)).number() == 2);
static_assert((4_q_km / 2_q_m).count() == 2); static_assert((4_q_km / 2_q_m).number() == 2);
static_assert((4000_q_m / 2_q_m).count() == 2000); static_assert((4000_q_m / 2_q_m).number() == 2000);
static_assert((1.5_q_m + 1_q_m).count() == 2.5); static_assert((1.5_q_m + 1_q_m).number() == 2.5);
static_assert((1.5_q_m + 1_q_km).count() == 1001.5); static_assert((1.5_q_m + 1_q_km).number() == 1001.5);
static_assert((1.5_q_km + 1_q_m).count() == 1501); static_assert((1.5_q_km + 1_q_m).number() == 1501);
static_assert((2.5_q_m - 1_q_m).count() == 1.5); static_assert((2.5_q_m - 1_q_m).number() == 1.5);
static_assert((1.5_q_km - 1_q_m).count() == 1499); static_assert((1.5_q_km - 1_q_m).number() == 1499);
static_assert((2.5_q_m * 2).count() == 5); static_assert((2.5_q_m * 2).number() == 5);
static_assert((2.5_q_m * quantity{2}).count() == 5); static_assert((2.5_q_m * quantity{2}).number() == 5);
static_assert((2.5_q_m * dimensionless<percent, int>(2)).count() == 5); static_assert((2.5_q_m * dimensionless<percent, int>(2)).number() == 5);
static_assert((2.5L * 2_q_m).count() == 5); static_assert((2.5L * 2_q_m).number() == 5);
static_assert((quantity{2.5L} * 2_q_m).count() == 5); static_assert((quantity{2.5L} * 2_q_m).number() == 5);
static_assert((dimensionless<percent, long double>(2.5L) * 2_q_m).count() == 5); static_assert((dimensionless<percent, long double>(2.5L) * 2_q_m).number() == 5);
static_assert((5._q_m / 2).count() == 2.5); static_assert((5._q_m / 2).number() == 2.5);
static_assert((5._q_m / quantity{2}).count() == 2.5); static_assert((5._q_m / quantity{2}).number() == 2.5);
static_assert((5._q_m / dimensionless<percent, int>(2)).count() == 2.5); static_assert((5._q_m / dimensionless<percent, int>(2)).number() == 2.5);
static_assert((5._q_km / 2_q_m).count() == 2.5); static_assert((5._q_km / 2_q_m).number() == 2.5);
static_assert((5000._q_m / 2_q_m).count() == 2500); static_assert((5000._q_m / 2_q_m).number() == 2500);
static_assert((1_q_m + 1.5_q_m).count() == 2.5); static_assert((1_q_m + 1.5_q_m).number() == 2.5);
static_assert((1_q_m + 1.5_q_km).count() == 1501); static_assert((1_q_m + 1.5_q_km).number() == 1501);
static_assert((1_q_km + 1.5_q_m).count() == 1001.5); static_assert((1_q_km + 1.5_q_m).number() == 1001.5);
static_assert((2_q_m - 1.5_q_m).count() == 0.5); static_assert((2_q_m - 1.5_q_m).number() == 0.5);
static_assert((1_q_km - 1.5_q_m).count() == 998.5); static_assert((1_q_km - 1.5_q_m).number() == 998.5);
static_assert((2_q_m * 2.5L).count() == 5); static_assert((2_q_m * 2.5L).number() == 5);
static_assert((2_q_m * quantity{2.5L}).count() == 5); static_assert((2_q_m * quantity{2.5L}).number() == 5);
static_assert((2_q_m * dimensionless<percent, long double>(2.5L)).count() == 5); static_assert((2_q_m * dimensionless<percent, long double>(2.5L)).number() == 5);
static_assert((2 * 2.5_q_m).count() == 5); static_assert((2 * 2.5_q_m).number() == 5);
static_assert((quantity{2} * 2.5_q_m).count() == 5); static_assert((quantity{2} * 2.5_q_m).number() == 5);
static_assert((dimensionless<percent, int>(2) * 2.5_q_m).count() == 5); static_assert((dimensionless<percent, int>(2) * 2.5_q_m).number() == 5);
static_assert((5_q_m / 2.5L).count() == 2); static_assert((5_q_m / 2.5L).number() == 2);
static_assert((5_q_m / quantity{2.5L}).count() == 2); static_assert((5_q_m / quantity{2.5L}).number() == 2);
static_assert((5_q_m / dimensionless<percent, long double>(2.5L)).count() == 2); static_assert((5_q_m / dimensionless<percent, long double>(2.5L)).number() == 2);
static_assert((5_q_km / 2.5_q_m).count() == 2); static_assert((5_q_km / 2.5_q_m).number() == 2);
static_assert((5000_q_m / 2.5_q_m).count() == 2000); static_assert((5000_q_m / 2.5_q_m).number() == 2000);
static_assert((7_q_m % 2).count() == 1); static_assert((7_q_m % 2).number() == 1);
static_assert((7_q_m % quantity{2}).count() == 1); static_assert((7_q_m % quantity{2}).number() == 1);
static_assert((7_q_m % dimensionless<percent, int>(2)).count() == 1); static_assert((7_q_m % dimensionless<percent, int>(2)).number() == 1);
static_assert((7_q_m % 2_q_m).count() == 1); static_assert((7_q_m % 2_q_m).number() == 1);
static_assert((7_q_km % 2000_q_m).count() == 1000); static_assert((7_q_km % 2000_q_m).number() == 1000);
static_assert((10_q_km2 * 10_q_km2) / 50_q_km2 == 2_q_km2); static_assert((10_q_km2 * 10_q_km2) / 50_q_km2 == 2_q_km2);
static_assert((10_q_km / 5_q_m).count() == 2); static_assert((10_q_km / 5_q_m).number() == 2);
static_assert(dimensionless<one>(10_q_km / 5_q_m).count() == 2000); static_assert(dimensionless<one>(10_q_km / 5_q_m).number() == 2000);
#if UNITS_DOWNCAST_MODE == 0 #if UNITS_DOWNCAST_MODE == 0
static_assert(quantity_cast<dim_one, one>(10_q_km / 5_q_m).count() == 2000); static_assert(quantity_cast<dim_one, one>(10_q_km / 5_q_m).number() == 2000);
#else #else
static_assert(quantity_cast<one>(10_q_km / 5_q_m).count() == 2000); static_assert(quantity_cast<one>(10_q_km / 5_q_m).number() == 2000);
#endif #endif
static_assert((10_q_s * 2_q_kHz).count() == 20); static_assert((10_q_s * 2_q_kHz).number() == 20);
// unit constants // unit constants
@ -592,13 +592,13 @@ static_assert(quantity(1) - 2.3 == quantity(1 - 2.3));
static_assert(1.2 + quantity(3) == quantity(1.2 + 3)); static_assert(1.2 + quantity(3) == quantity(1.2 + 3));
static_assert(1.2 - quantity(3) == quantity(1.2 - 3)); static_assert(1.2 - quantity(3) == quantity(1.2 - 3));
static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} + quantity{std::uint8_t(0)}).count()), int>); static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} + quantity{std::uint8_t(0)}).number()), int>);
static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} - quantity{std::uint8_t(0)}).count()), int>); static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} - quantity{std::uint8_t(0)}).number()), int>);
static_assert((quantity{std::uint8_t(128)} + quantity{std::uint8_t(128)}).count() == static_assert((quantity{std::uint8_t(128)} + quantity{std::uint8_t(128)}).number() ==
std::uint8_t(128) + std::uint8_t(128)); std::uint8_t(128) + std::uint8_t(128));
static_assert((quantity{std::uint8_t(0)} - quantity{std::uint8_t(1)}).count() == std::uint8_t(0) - std::uint8_t(1)); static_assert((quantity{std::uint8_t(0)} - quantity{std::uint8_t(1)}).number() == std::uint8_t(0) - std::uint8_t(1));
static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} % quantity{std::uint8_t(0)}).count()), static_assert(is_same_v<decltype((quantity{std::uint8_t(0)} % quantity{std::uint8_t(0)}).number()),
decltype(std::uint8_t(0) % std::uint8_t(0))>); decltype(std::uint8_t(0) % std::uint8_t(0))>);
static_assert(quantity{2} * (1 * m) == 2_q_m); static_assert(quantity{2} * (1 * m) == 2_q_m);
@ -731,13 +731,13 @@ static_assert(invalid_dimensionless_operations<int>);
static_assert(compare<decltype(10_q_km / 5_q_km), quantity<dim_one, one, std::int64_t>>); static_assert(compare<decltype(10_q_km / 5_q_km), quantity<dim_one, one, std::int64_t>>);
#if UNITS_DOWNCAST_MODE == 0 #if UNITS_DOWNCAST_MODE == 0
static_assert(quantity_cast<dim_one, percent>(50._q_m / 100._q_m).count() == 50); static_assert(quantity_cast<dim_one, percent>(50._q_m / 100._q_m).number() == 50);
#else #else
static_assert(quantity_cast<percent>(50._q_m / 100._q_m).count() == 50); static_assert(quantity_cast<percent>(50._q_m / 100._q_m).number() == 50);
#endif #endif
static_assert(50._q_m / 100._q_m == dimensionless<percent>(50)); static_assert(50._q_m / 100._q_m == dimensionless<percent>(50));
static_assert(dimensionless<one>(dimensionless<percent>(50)).count() == 0.5); static_assert(dimensionless<one>(dimensionless<percent>(50)).number() == 0.5);
//////////////// ////////////////
@ -755,13 +755,13 @@ static_assert(2_q_dm3 + 2_q_cm3 == 2002_q_ml);
// quantity_cast // quantity_cast
////////////////// //////////////////
static_assert(quantity_cast<length<metre, int>>(2_q_km).count() == 2000); static_assert(quantity_cast<length<metre, int>>(2_q_km).number() == 2000);
static_assert(quantity_cast<length<kilometre, int>>(2000_q_m).count() == 2); static_assert(quantity_cast<length<kilometre, int>>(2000_q_m).number() == 2);
static_assert(quantity_cast<length<metre, int>>(1.23_q_m).count() == 1); static_assert(quantity_cast<length<metre, int>>(1.23_q_m).number() == 1);
static_assert(quantity_cast<metre>(2_q_km).count() == 2000); static_assert(quantity_cast<metre>(2_q_km).number() == 2000);
static_assert(quantity_cast<kilometre>(2000_q_m).count() == 2); static_assert(quantity_cast<kilometre>(2000_q_m).number() == 2);
static_assert(quantity_cast<int>(1.23_q_m).count() == 1); static_assert(quantity_cast<int>(1.23_q_m).number() == 1);
static_assert(quantity_cast<dim_speed, kilometre_per_hour>(2000.0_q_m / 3600.0_q_s).count() == 2); static_assert(quantity_cast<dim_speed, kilometre_per_hour>(2000.0_q_m / 3600.0_q_s).number() == 2);
static_assert(quantity_cast<dim_length>(1 * cgs_cm) == 1 * cm); static_assert(quantity_cast<dim_length>(1 * cgs_cm) == 1 * cm);

View File

@ -105,7 +105,7 @@ static_assert(120 / 1_q_min == 2_q_Hz);
static_assert(1000 / 1_q_s == 1_q_kHz); static_assert(1000 / 1_q_s == 1_q_kHz);
static_assert(1 / 1_q_ms == 1_q_kHz); static_assert(1 / 1_q_ms == 1_q_kHz);
static_assert(3.2_q_GHz == 3'200'000'000_q_Hz); static_assert(3.2_q_GHz == 3'200'000'000_q_Hz);
static_assert((10_q_Hz * 1_q_min).count() == 10); static_assert((10_q_Hz * 1_q_min).number() == 10);
static_assert(10_q_Hz * 1_q_min == dimensionless<scaled_unit<ratio(60), one>>(10)); static_assert(10_q_Hz * 1_q_min == dimensionless<scaled_unit<ratio(60), one>>(10));
static_assert(10_q_Hz * 1_q_min == dimensionless<one>(600)); static_assert(10_q_Hz * 1_q_min == dimensionless<one>(600));
static_assert(2 / 1_q_Hz == 2_q_s); static_assert(2 / 1_q_Hz == 2_q_s);