mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 12:24:26 +02:00
refactor: remove operator/(Rep, reference)
Addresses https://github.com/mpusz/units/pull/261#discussion_r597289047.
This commit is contained in:
committed by
Mateusz Pusz
parent
9da39070ed
commit
f0cfc14b83
@@ -104,8 +104,8 @@ With the above our code can look as follows::
|
|||||||
|
|
||||||
.. important::
|
.. important::
|
||||||
|
|
||||||
``km * 3`` or ``s / 4`` syntax is not allowed.
|
The following syntaxes are not allowed:
|
||||||
Neither is ``70 * km / h``, but ``70 * (km / h)`` is.
|
``2 / s``, ``km * 3``, ``s / 4``, ``70 * km / h``.
|
||||||
|
|
||||||
It is also allowed to easily define custom quantity references from existing ones::
|
It is also allowed to easily define custom quantity references from existing ones::
|
||||||
|
|
||||||
|
@@ -85,8 +85,8 @@ using reference_divide = detail::reference_divide_impl<
|
|||||||
* constexpr auto mph = mi / h;
|
* constexpr auto mph = mi / h;
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* `km * 3` or `s / 4` syntax is not allowed for quantity creation.
|
* The following syntaxes are not allowed:
|
||||||
* Neither is `70 * km / h`, but `70 * (km / h)` is.
|
* `2 / s`, `km * 3`, `s / 4`, `70 * km / h`.
|
||||||
*/
|
*/
|
||||||
template<Dimension D, UnitOf<D> U>
|
template<Dimension D, UnitOf<D> U>
|
||||||
struct reference {
|
struct reference {
|
||||||
@@ -108,14 +108,7 @@ struct reference {
|
|||||||
return quantity<D, U, Rep>(lhs);
|
return quantity<D, U, Rep>(lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<QuantityValue Rep>
|
|
||||||
[[nodiscard]] friend constexpr Quantity auto operator/(const Rep& lhs, reference)
|
|
||||||
{
|
|
||||||
return lhs / quantity<D, U, Rep>::one();
|
|
||||||
}
|
|
||||||
|
|
||||||
friend void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, reference) = delete;
|
friend void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, reference) = delete;
|
||||||
friend void /*Use `q / (1 * r)` rather than `q / r`.*/ operator/(Quantity auto, reference) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// type traits
|
// type traits
|
||||||
|
@@ -578,28 +578,28 @@ static_assert(same(width<metre, double>(2. * m) / quantity_kind<downcast_kind<wi
|
|||||||
width<metre, double>(2. / 3 * m)));
|
width<metre, double>(2. / 3 * m)));
|
||||||
|
|
||||||
static_assert(same(2 / quantity_kind<time_kind, second, int>(3 * s),
|
static_assert(same(2 / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / (1 * s))));
|
||||||
static_assert(same(2 / quantity_kind<time_kind, second, double>(3. * s),
|
static_assert(same(2 / quantity_kind<time_kind, second, double>(3. * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
static_assert(same(2. / quantity_kind<time_kind, second, int>(3 * s),
|
static_assert(same(2. / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
|
|
||||||
static_assert(same(quantity(2) / quantity_kind<time_kind, second, int>(3 * s),
|
static_assert(same(quantity(2) / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / (1 * s))));
|
||||||
static_assert(same(quantity(2) / quantity_kind<time_kind, second, double>(3. * s),
|
static_assert(same(quantity(2) / quantity_kind<time_kind, second, double>(3. * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
static_assert(same(quantity(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
static_assert(same(quantity(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, int>(3 * s),
|
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / (1 * s))));
|
||||||
static_assert(
|
static_assert(
|
||||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, double>(3. * s),
|
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, double>(3. * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
static_assert(
|
static_assert(
|
||||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, double>(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, double>(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
||||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / s)));
|
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||||
|
|
||||||
static_assert(same(height<metre, int>(2 * m) / (3 * s), rate_of_climb<metre_per_second, int>(0 * (m / s))));
|
static_assert(same(height<metre, int>(2 * m) / (3 * s), rate_of_climb<metre_per_second, int>(0 * (m / s))));
|
||||||
static_assert(same(height<metre, int>(2 * m) / (3. * s), rate_of_climb<metre_per_second, double>(2 / 3. * (m / s))));
|
static_assert(same(height<metre, int>(2 * m) / (3. * s), rate_of_climb<metre_per_second, double>(2 / 3. * (m / s))));
|
||||||
|
@@ -45,6 +45,7 @@ static_assert(2 * m == 2_q_m);
|
|||||||
static_assert(2 * s == 2_q_s);
|
static_assert(2 * s == 2_q_s);
|
||||||
template<auto& s>
|
template<auto& s>
|
||||||
concept invalid_operations = requires {
|
concept invalid_operations = requires {
|
||||||
|
requires !requires { 2 / s; };
|
||||||
requires !requires { s / 2; };
|
requires !requires { s / 2; };
|
||||||
requires !requires { s * 2; };
|
requires !requires { s * 2; };
|
||||||
requires !requires { s + 2; };
|
requires !requires { s + 2; };
|
||||||
@@ -66,7 +67,6 @@ static_assert(invalid_operations<s>);
|
|||||||
|
|
||||||
static_assert(2_q_m / (1 * s) == 2_q_m_per_s);
|
static_assert(2_q_m / (1 * s) == 2_q_m_per_s);
|
||||||
static_assert(2 * (m / s) == 2_q_m_per_s);
|
static_assert(2 * (m / s) == 2_q_m_per_s);
|
||||||
static_assert(2 / (s / m) == 2_q_m_per_s);
|
|
||||||
|
|
||||||
#if !(UNITS_COMP_GCC == 10 && UNITS_COMP_GCC_MINOR == 1) // GCC 10.1.0 ICEs
|
#if !(UNITS_COMP_GCC == 10 && UNITS_COMP_GCC_MINOR == 1) // GCC 10.1.0 ICEs
|
||||||
constexpr auto m_per_s = m / s;
|
constexpr auto m_per_s = m / s;
|
||||||
|
Reference in New Issue
Block a user