From 2adc9344ea23962afda3f70b58099dfa5a785f06 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 1 Jun 2024 13:36:22 +0200 Subject: [PATCH] refactor: some TODO comment addressed or removed --- src/core/include/mp-units/ext/algorithm.h | 5 +++-- src/core/include/mp-units/framework/magnitude.h | 14 ++------------ .../include/mp-units/framework/quantity_spec.h | 5 ----- src/core/include/mp-units/framework/symbol_text.h | 1 - test/static/quantity_test.cpp | 2 ++ 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/core/include/mp-units/ext/algorithm.h b/src/core/include/mp-units/ext/algorithm.h index 4e9f77c0..6c50dedc 100644 --- a/src/core/include/mp-units/ext/algorithm.h +++ b/src/core/include/mp-units/ext/algorithm.h @@ -20,8 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// Copy-pasted C++ standard libraries to be replaced with `import std;` when available -// `#include ` is too heavy to do in every translation unit +// Copy-pasted C++ standard libraries +// TODO To be replaced with `import std;` when available +// `#include ` is too heavy to do in every translation unit #pragma once diff --git a/src/core/include/mp-units/framework/magnitude.h b/src/core/include/mp-units/framework/magnitude.h index 5fd09326..2b55017f 100644 --- a/src/core/include/mp-units/framework/magnitude.h +++ b/src/core/include/mp-units/framework/magnitude.h @@ -295,17 +295,8 @@ template constexpr auto checked_square = [checked_multiply](auto a) { return checked_multiply(a, a); }; - // TODO(chogg): Unify this implementation with the one in pow.h. That one takes its exponent as a - // template parameter, rather than a function parameter. - - if (exp == 0) { - return T{1}; - } - - if (exp % 2 == 1) { - return checked_multiply(base, int_power(base, exp - 1)); - } - + if (exp == 0) return T{1}; + if (exp % 2 == 1) return checked_multiply(base, int_power(base, exp - 1)); return checked_square(int_power(base, exp / 2)); } @@ -340,7 +331,6 @@ template // The input is the desired result, but in a (wider) intermediate type. The point of this function // is to cast to the desired type, but avoid overflow in doing so. template -// TODO(chogg): Migrate this to use `treat_as_floating_point`. requires(!std::is_integral_v || std::is_integral_v) [[nodiscard]] consteval To checked_static_cast(From x) { diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 80ae5d79..383a61f3 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -552,11 +552,6 @@ template requires detail::non_zero [[nodiscard]] consteval QuantitySpec auto pow(Q q) { - // TODO Does the below make sense? - // `2 * 2` should compare to `4` - // `2 * one * (2 * one)` should compare to `4 * one` - // `2 * rad * (2 * rad)` should compare to `4 * rad^2` - // all are dimensionless quantities :-( if constexpr (Num == 0 || Q{} == dimensionless) return dimensionless; else if constexpr (detail::ratio{Num, Den} == 1) diff --git a/src/core/include/mp-units/framework/symbol_text.h b/src/core/include/mp-units/framework/symbol_text.h index 40f93a9a..e89aab96 100644 --- a/src/core/include/mp-units/framework/symbol_text.h +++ b/src/core/include/mp-units/framework/symbol_text.h @@ -24,7 +24,6 @@ #pragma once // IWYU pragma: private, include -// TODO use when moved to C++20 modules (parsing takes too long for each translation unit) #include #include #include diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 5cea40a5..5d9161be 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -744,6 +744,8 @@ static_assert(4 / (2 * one) == 2 * one); static_assert(4 * one / 2 == 2 * one); static_assert(4 * one % (2 * one) == 0 * one); +static_assert(2 * rad * (2 * rad) == 4 * pow<2>(rad)); + // modulo arithmetics static_assert(5 * h % (120 * min) == 60 * min); static_assert(300 * min % (2 * h) == 60 * min);