diff --git a/docs/framework/quantities.rst b/docs/framework/quantities.rst index c8660688..0367bd77 100644 --- a/docs/framework/quantities.rst +++ b/docs/framework/quantities.rst @@ -104,8 +104,8 @@ With the above our code can look as follows:: .. important:: - ``km * 3`` or ``s / 4`` syntax is not allowed. - Neither is ``70 * km / h``, but ``70 * (km / h)`` is. + The following syntaxes are not allowed: + ``2 / s``, ``km * 3``, ``s / 4``, ``70 * km / h``. It is also allowed to easily define custom quantity references from existing ones:: diff --git a/src/core/include/units/reference.h b/src/core/include/units/reference.h index 53c2476c..391f8d7a 100644 --- a/src/core/include/units/reference.h +++ b/src/core/include/units/reference.h @@ -85,8 +85,8 @@ using reference_divide = detail::reference_divide_impl< * constexpr auto mph = mi / h; * @endcode * - * `km * 3` or `s / 4` syntax is not allowed for quantity creation. - * Neither is `70 * km / h`, but `70 * (km / h)` is. + * The following syntaxes are not allowed: + * `2 / s`, `km * 3`, `s / 4`, `70 * km / h`. */ template U> struct reference { @@ -108,14 +108,7 @@ struct reference { return quantity(lhs); } - template - [[nodiscard]] friend constexpr Quantity auto operator/(const Rep& lhs, reference) - { - return lhs / quantity::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; }; // type traits diff --git a/test/unit_test/static/quantity_kind_test.cpp b/test/unit_test/static/quantity_kind_test.cpp index 25891b9e..521b2bea 100644 --- a/test/unit_test/static/quantity_kind_test.cpp +++ b/test/unit_test/static/quantity_kind_test.cpp @@ -578,28 +578,28 @@ static_assert(same(width(2. * m) / quantity_kind(2. / 3 * m))); static_assert(same(2 / quantity_kind(3 * s), - quantity_kind, hertz, int>(2 / 3 / s))); + quantity_kind, hertz, int>(2 / 3 / (1 * s)))); static_assert(same(2 / quantity_kind(3. * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert(same(2. / quantity_kind(3 * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert(same(quantity(2) / quantity_kind(3 * s), - quantity_kind, hertz, int>(2 / 3 / s))); + quantity_kind, hertz, int>(2 / 3 / (1 * s)))); static_assert(same(quantity(2) / quantity_kind(3. * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert(same(quantity(2.) / quantity_kind(3 * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert( same(quantity_kind, one, int>(2) / quantity_kind(3 * s), - quantity_kind, hertz, int>(2 / 3 / s))); + quantity_kind, hertz, int>(2 / 3 / (1 * s)))); static_assert( same(quantity_kind, one, int>(2) / quantity_kind(3. * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert( same(quantity_kind, one, double>(2.) / quantity_kind(3 * s), - quantity_kind, hertz, double>(2 / 3. / s))); + quantity_kind, hertz, double>(2 / 3. / (1 * s)))); static_assert(same(height(2 * m) / (3 * s), rate_of_climb(0 * (m / s)))); static_assert(same(height(2 * m) / (3. * s), rate_of_climb(2 / 3. * (m / s)))); diff --git a/test/unit_test/static/references_test.cpp b/test/unit_test/static/references_test.cpp index 86ceb728..e4b76c5a 100644 --- a/test/unit_test/static/references_test.cpp +++ b/test/unit_test/static/references_test.cpp @@ -45,6 +45,7 @@ static_assert(2 * m == 2_q_m); static_assert(2 * s == 2_q_s); template concept invalid_operations = requires { + requires !requires { 2 / s; }; requires !requires { s / 2; }; requires !requires { s * 2; }; requires !requires { s + 2; }; @@ -66,7 +67,6 @@ static_assert(invalid_operations); 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 / (s / m) == 2_q_m_per_s); #if !(UNITS_COMP_GCC == 10 && UNITS_COMP_GCC_MINOR == 1) // GCC 10.1.0 ICEs constexpr auto m_per_s = m / s;