forked from mpusz/mp-units
refactor: some TODO comment addressed or removed
This commit is contained in:
@@ -20,8 +20,9 @@
|
|||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
// Copy-pasted C++ standard libraries to be replaced with `import std;` when available
|
// Copy-pasted C++ standard libraries
|
||||||
// `#include <algorithm.h>` is too heavy to do in every translation unit
|
// TODO To be replaced with `import std;` when available
|
||||||
|
// `#include <algorithm.h>` is too heavy to do in every translation unit
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
@@ -295,17 +295,8 @@ template<typename T>
|
|||||||
|
|
||||||
constexpr auto checked_square = [checked_multiply](auto a) { return checked_multiply(a, a); };
|
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
|
if (exp == 0) return T{1};
|
||||||
// template parameter, rather than a function parameter.
|
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));
|
return checked_square(int_power(base, exp / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +331,6 @@ template<typename T>
|
|||||||
// The input is the desired result, but in a (wider) intermediate type. The point of this function
|
// 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.
|
// is to cast to the desired type, but avoid overflow in doing so.
|
||||||
template<typename To, typename From>
|
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>)
|
requires(!std::is_integral_v<To> || std::is_integral_v<From>)
|
||||||
[[nodiscard]] consteval To checked_static_cast(From x)
|
[[nodiscard]] consteval To checked_static_cast(From x)
|
||||||
{
|
{
|
||||||
|
@@ -552,11 +552,6 @@ template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q>
|
|||||||
requires detail::non_zero<Den>
|
requires detail::non_zero<Den>
|
||||||
[[nodiscard]] consteval QuantitySpec auto pow(Q q)
|
[[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)
|
if constexpr (Num == 0 || Q{} == dimensionless)
|
||||||
return dimensionless;
|
return dimensionless;
|
||||||
else if constexpr (detail::ratio{Num, Den} == 1)
|
else if constexpr (detail::ratio{Num, Den} == 1)
|
||||||
|
@@ -24,7 +24,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// IWYU pragma: private, include <mp-units/framework.h>
|
// 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/hacks.h>
|
||||||
#include <mp-units/bits/module_macros.h>
|
#include <mp-units/bits/module_macros.h>
|
||||||
#include <mp-units/compat_macros.h>
|
#include <mp-units/compat_macros.h>
|
||||||
|
@@ -744,6 +744,8 @@ static_assert(4 / (2 * one) == 2 * one);
|
|||||||
static_assert(4 * one / 2 == 2 * one);
|
static_assert(4 * one / 2 == 2 * one);
|
||||||
static_assert(4 * one % (2 * one) == 0 * one);
|
static_assert(4 * one % (2 * one) == 0 * one);
|
||||||
|
|
||||||
|
static_assert(2 * rad * (2 * rad) == 4 * pow<2>(rad));
|
||||||
|
|
||||||
// modulo arithmetics
|
// modulo arithmetics
|
||||||
static_assert(5 * h % (120 * min) == 60 * min);
|
static_assert(5 * h % (120 * min) == 60 * min);
|
||||||
static_assert(300 * min % (2 * h) == 60 * min);
|
static_assert(300 * min % (2 * h) == 60 * min);
|
||||||
|
Reference in New Issue
Block a user