mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
fix: integral representations allowed for irrational canonical units
Resolves #485
This commit is contained in:
@@ -36,7 +36,6 @@ class quantity;
|
||||
template<auto R, typename Rep>
|
||||
#else
|
||||
template<Reference auto R, typename Rep>
|
||||
requires quantity<R, std::remove_cvref_t<Rep>>::_rep_safe_constructible_
|
||||
#endif
|
||||
[[nodiscard]] constexpr quantity<R, std::remove_cvref_t<Rep>> make_quantity(Rep&& v);
|
||||
|
||||
|
@@ -43,11 +43,6 @@ namespace mp_units {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T, typename Arg, auto U>
|
||||
concept RepSafeConstructibleFrom = Unit<std::remove_const_t<decltype(U)>> && std::constructible_from<T, Arg> &&
|
||||
(treat_as_floating_point<T> || (!treat_as_floating_point<std::remove_cvref_t<Arg>> &&
|
||||
is_rational(get_canonical_unit(U).mag)));
|
||||
|
||||
template<auto UFrom, auto UTo>
|
||||
concept IntegralConversionFactor = Unit<decltype(UFrom)> && Unit<decltype(UTo)> &&
|
||||
is_integral(get_canonical_unit(UFrom).mag / get_canonical_unit(UTo).mag);
|
||||
@@ -99,9 +94,6 @@ public:
|
||||
static constexpr Unit auto unit = get_unit(reference);
|
||||
using rep = Rep;
|
||||
|
||||
// helper used to constrain `make_quantity()` and `operator*(Representation, Unit)`
|
||||
static constexpr bool _rep_safe_constructible_ = detail::RepSafeConstructibleFrom<Rep, Rep&&, unit>;
|
||||
|
||||
// static member functions
|
||||
[[nodiscard]] static constexpr quantity zero() noexcept
|
||||
requires requires { quantity_values<rep>::zero(); }
|
||||
@@ -329,12 +321,11 @@ private:
|
||||
template<auto R2, typename Rep2>
|
||||
#else
|
||||
template<Reference auto R2, typename Rep2>
|
||||
requires quantity<R2, std::remove_cvref_t<Rep2>>::_rep_safe_constructible_
|
||||
#endif
|
||||
friend constexpr quantity<R2, std::remove_cvref_t<Rep2>> make_quantity(Rep2&&);
|
||||
|
||||
template<typename Value>
|
||||
requires detail::RepSafeConstructibleFrom<rep, Value&&, unit>
|
||||
requires std::constructible_from<rep, Value&&>
|
||||
constexpr explicit quantity(Value&& v) : value_(std::forward<Value>(v))
|
||||
{
|
||||
}
|
||||
@@ -443,7 +434,6 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
template<auto R, typename Rep>
|
||||
#else
|
||||
template<Reference auto R, typename Rep>
|
||||
requires quantity<R, std::remove_cvref_t<Rep>>::_rep_safe_constructible_
|
||||
#endif
|
||||
[[nodiscard]] constexpr quantity<R, std::remove_cvref_t<Rep>> make_quantity(Rep&& v)
|
||||
{
|
||||
|
@@ -159,7 +159,6 @@ template<Reference auto R, RepresentationOf<get_quantity_spec(R).character> Rep>
|
||||
class quantity;
|
||||
|
||||
template<typename Rep, Reference R>
|
||||
requires quantity<R{}, std::remove_cvref_t<Rep>>::_rep_safe_constructible_
|
||||
[[nodiscard]] constexpr quantity<R{}, std::remove_cvref_t<Rep>> operator*(Rep&& lhs, R)
|
||||
{
|
||||
return make_quantity<R{}>(std::forward<Rep>(lhs));
|
||||
|
Reference in New Issue
Block a user