Skip to content

Commit

Permalink
refactor: some TODO comment addressed or removed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Jun 1, 2024
1 parent 3c8a021 commit 2adc934
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/core/include/mp-units/ext/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm.h>` is too heavy to do in every translation unit
// Copy-pasted C++ standard libraries
// TODO To be replaced with `import std;` when available
// `#include <algorithm.h>` is too heavy to do in every translation unit

#pragma once

Expand Down
14 changes: 2 additions & 12 deletions src/core/include/mp-units/framework/magnitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,8 @@ template<typename T>

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));
}

Expand Down Expand Up @@ -340,7 +331,6 @@ template<typename T>
// 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<typename To, typename From>
// TODO(chogg): Migrate this to use `treat_as_floating_point`.
requires(!std::is_integral_v<To> || std::is_integral_v<From>)
[[nodiscard]] consteval To checked_static_cast(From x)
{
Expand Down
5 changes: 0 additions & 5 deletions src/core/include/mp-units/framework/quantity_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,6 @@ template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q>
requires detail::non_zero<Den>
[[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)
Expand Down
1 change: 0 additions & 1 deletion src/core/include/mp-units/framework/symbol_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#pragma once

// IWYU pragma: private, include <mp-units/framework.h>
// TODO use <algorithm> when moved to C++20 modules (parsing takes too long for each translation unit)
#include <mp-units/bits/hacks.h>
#include <mp-units/bits/module_macros.h>
#include <mp-units/compat_macros.h>
Expand Down
2 changes: 2 additions & 0 deletions test/static/quantity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2adc934

Please sign in to comment.