mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-09 23:24:27 +02:00
refactor: math_concepts usage
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <units/bits/external/type_list.h>
|
||||
#include <units/bits/external/type_traits.h>
|
||||
#include <units/bits/math_concepts.h>
|
||||
#include <units/ratio.h>
|
||||
|
||||
namespace units {
|
||||
@@ -65,10 +66,10 @@ template<>
|
||||
inline constexpr bool valid_ratio<0, 0> = false;
|
||||
|
||||
template<int Num, int... Den>
|
||||
inline constexpr bool positive_ratio = (Num > 0);
|
||||
inline constexpr bool positive_ratio = gt_zero<Num>;
|
||||
|
||||
template<int Num, int Den>
|
||||
inline constexpr bool positive_ratio<Num, Den> = (Num * Den > 0);
|
||||
inline constexpr bool positive_ratio<Num, Den> = gt_zero<Num * Den>;
|
||||
|
||||
template<int Num, int... Den>
|
||||
inline constexpr bool ratio_one = false;
|
||||
|
@@ -26,10 +26,10 @@
|
||||
|
||||
namespace units::detail {
|
||||
|
||||
template<std::intmax_t N>
|
||||
template<auto N>
|
||||
concept gt_zero = (N > 0);
|
||||
|
||||
template<std::intmax_t N>
|
||||
template<auto N>
|
||||
concept non_zero = (N != 0);
|
||||
|
||||
} // namespace units::detail
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <units/bits/external/hacks.h>
|
||||
#include <units/bits/external/type_name.h>
|
||||
#include <units/bits/external/type_traits.h>
|
||||
#include <units/bits/math_concepts.h>
|
||||
#include <units/bits/prime.h>
|
||||
#include <units/ratio.h>
|
||||
#include <concepts>
|
||||
@@ -732,7 +733,7 @@ namespace detail {
|
||||
|
||||
// Helper to perform prime factorization at compile time.
|
||||
template<std::intmax_t N>
|
||||
requires(N > 0)
|
||||
requires gt_zero<N>
|
||||
struct prime_factorization {
|
||||
[[nodiscard]] static consteval std::intmax_t get_or_compute_first_factor()
|
||||
{
|
||||
@@ -767,16 +768,15 @@ inline constexpr auto prime_factorization_v = prime_factorization<N>::value;
|
||||
* This will be the main way end users create Magnitudes. They should rarely (if ever) create a magnitude<...> by
|
||||
* manually adding base powers.
|
||||
*/
|
||||
|
||||
template<ratio R>
|
||||
requires(R.num > 0)
|
||||
requires detail::gt_zero<R.num>
|
||||
inline constexpr Magnitude auto mag = detail::prime_factorization_v<R.num> / detail::prime_factorization_v<R.den>;
|
||||
|
||||
/**
|
||||
* @brief Create a Magnitude which is some rational number raised to a rational power.
|
||||
*/
|
||||
template<ratio Base, ratio Pow>
|
||||
requires(Base.num > 0)
|
||||
requires detail::gt_zero<Base.num>
|
||||
inline constexpr Magnitude auto mag_power = pow<Pow>(mag<Base>);
|
||||
|
||||
namespace detail {
|
||||
|
Reference in New Issue
Block a user