Dimension template parameter removed from quantity
This commit is contained in:
1 parent
03a22cba2a
commit
eeb4c9c951
16 files changed
+328
-409
No files matched your search
@@ -32,9 +32,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Area = Quantity<T> && std::Same<typename T::dimension, dimension_area>;
|
||||
|
||||
template<Unit U = struct square_meter, Number Rep = double>
|
||||
using area = quantity<dimension_area, U, Rep>;
|
||||
|
||||
struct square_millimeter : derived_unit<dimension_area, millimeter> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_millimeter>> : downcast_to<square_millimeter> {};
|
||||
|
||||
@@ -53,20 +50,20 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// sq_mm
|
||||
constexpr auto operator""_sq_mm(unsigned long long l) { return area<square_millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_mm(long double l) { return area<square_millimeter, long double>(l); }
|
||||
constexpr auto operator""_sq_mm(unsigned long long l) { return quantity<square_millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_mm(long double l) { return quantity<square_millimeter, long double>(l); }
|
||||
|
||||
// sq_cm
|
||||
constexpr auto operator""_sq_cm(unsigned long long l) { return area<square_centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_cm(long double l) { return area<square_centimeter, long double>(l); }
|
||||
constexpr auto operator""_sq_cm(unsigned long long l) { return quantity<square_centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_cm(long double l) { return quantity<square_centimeter, long double>(l); }
|
||||
|
||||
// sq_m
|
||||
constexpr auto operator""_sq_m(unsigned long long l) { return area<square_meter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_m(long double l) { return area<square_meter, long double>(l); }
|
||||
constexpr auto operator""_sq_m(unsigned long long l) { return quantity<square_meter, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_m(long double l) { return quantity<square_meter, long double>(l); }
|
||||
|
||||
// sq_km
|
||||
constexpr auto operator""_sq_km(unsigned long long l) { return area<square_kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_km(long double l) { return area<square_kilometer, long double>(l); }
|
||||
constexpr auto operator""_sq_km(unsigned long long l) { return quantity<square_kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""_sq_km(long double l) { return quantity<square_kilometer, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace std {
|
||||
using type_identity_t = typename type_identity<T>::type;
|
||||
|
||||
#endif // UNITS_HAS_STD_TYPE_IDENTITY
|
||||
|
||||
// concepts
|
||||
using experimental::ranges::Same;
|
||||
using experimental::ranges::Integral;
|
||||
@@ -45,4 +46,4 @@ namespace std {
|
||||
using experimental::ranges::StrictTotallyOrdered;
|
||||
using experimental::ranges::ConvertibleTo;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,17 +33,14 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Current = Quantity<T> && std::Same<typename T::dimension, dimension_current>;
|
||||
|
||||
template<Unit U = struct ampere, Number Rep = double>
|
||||
using current = quantity<dimension_current, U, Rep>;
|
||||
|
||||
struct ampere : unit<dimension_current> {};
|
||||
template<> struct downcasting_traits<downcast_from<ampere>> : downcast_to<ampere> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// A
|
||||
constexpr auto operator""_A(unsigned long long l) { return current<ampere, std::int64_t>(l); }
|
||||
constexpr auto operator""_A(long double l) { return current<ampere, long double>(l); }
|
||||
constexpr auto operator""_A(unsigned long long l) { return quantity<ampere, std::int64_t>(l); }
|
||||
constexpr auto operator""_A(long double l) { return quantity<ampere, long double>(l); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Frequency = Quantity<T> && std::Same<typename T::dimension, dimension_frequency>;
|
||||
|
||||
template<Unit U = struct hertz, Number Rep = double>
|
||||
using frequency = quantity<dimension_frequency, U, Rep>;
|
||||
|
||||
struct hertz : derived_unit<dimension_frequency, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<hertz>> : downcast_to<hertz> {};
|
||||
|
||||
@@ -57,28 +54,28 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// mHz
|
||||
constexpr auto operator""_mHz(unsigned long long l) { return frequency<millihertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_mHz(long double l) { return frequency<millihertz, long double>(l); }
|
||||
constexpr auto operator""_mHz(unsigned long long l) { return quantity<millihertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_mHz(long double l) { return quantity<millihertz, long double>(l); }
|
||||
|
||||
// Hz
|
||||
constexpr auto operator""_Hz(unsigned long long l) { return frequency<hertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_Hz(long double l) { return frequency<hertz, long double>(l); }
|
||||
constexpr auto operator""_Hz(unsigned long long l) { return quantity<hertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_Hz(long double l) { return quantity<hertz, long double>(l); }
|
||||
|
||||
// kHz
|
||||
constexpr auto operator""_kHz(unsigned long long l) { return frequency<kilohertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_kHz(long double l) { return frequency<kilohertz, long double>(l); }
|
||||
constexpr auto operator""_kHz(unsigned long long l) { return quantity<kilohertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_kHz(long double l) { return quantity<kilohertz, long double>(l); }
|
||||
|
||||
// MHz
|
||||
constexpr auto operator""_MHz(unsigned long long l) { return frequency<megahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_MHz(long double l) { return frequency<megahertz, long double>(l); }
|
||||
constexpr auto operator""_MHz(unsigned long long l) { return quantity<megahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_MHz(long double l) { return quantity<megahertz, long double>(l); }
|
||||
|
||||
// GHz
|
||||
constexpr auto operator""_GHz(unsigned long long l) { return frequency<gigahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_GHz(long double l) { return frequency<gigahertz, long double>(l); }
|
||||
constexpr auto operator""_GHz(unsigned long long l) { return quantity<gigahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_GHz(long double l) { return quantity<gigahertz, long double>(l); }
|
||||
|
||||
// THz
|
||||
constexpr auto operator""_THz(unsigned long long l) { return frequency<terahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_THz(long double l) { return frequency<terahertz, long double>(l); }
|
||||
constexpr auto operator""_THz(unsigned long long l) { return quantity<terahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_THz(long double l) { return quantity<terahertz, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
+16
-19
@@ -33,9 +33,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Length = Quantity<T> && std::Same<typename T::dimension, dimension_length>;
|
||||
|
||||
template<Unit U = struct meter, Number Rep = double>
|
||||
using length = quantity<dimension_length, U, Rep>;
|
||||
|
||||
// SI units
|
||||
struct meter : unit<dimension_length> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter>> : downcast_to<meter> {};
|
||||
@@ -52,20 +49,20 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// mm
|
||||
constexpr auto operator""_mm(unsigned long long l) { return length<millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_mm(long double l) { return length<millimeter, long double>(l); }
|
||||
constexpr auto operator""_mm(unsigned long long l) { return quantity<millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_mm(long double l) { return quantity<millimeter, long double>(l); }
|
||||
|
||||
// cm
|
||||
constexpr auto operator""_cm(unsigned long long l) { return length<centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_cm(long double l) { return length<centimeter, long double>(l); }
|
||||
constexpr auto operator""_cm(unsigned long long l) { return quantity<centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_cm(long double l) { return quantity<centimeter, long double>(l); }
|
||||
|
||||
// m
|
||||
constexpr auto operator""_m(unsigned long long l) { return length<meter, std::int64_t>(l); }
|
||||
constexpr auto operator""_m(long double l) { return length<meter, long double>(l); }
|
||||
constexpr auto operator""_m(unsigned long long l) { return quantity<meter, std::int64_t>(l); }
|
||||
constexpr auto operator""_m(long double l) { return quantity<meter, long double>(l); }
|
||||
|
||||
// km
|
||||
constexpr auto operator""_km(unsigned long long l) { return length<kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""_km(long double l) { return length<kilometer, long double>(l); }
|
||||
constexpr auto operator""_km(unsigned long long l) { return quantity<kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""_km(long double l) { return quantity<kilometer, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
@@ -85,20 +82,20 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// yd
|
||||
constexpr auto operator""_yd(unsigned long long l) { return length<yard, std::int64_t>(l); }
|
||||
constexpr auto operator""_yd(long double l) { return length<yard, long double>(l); }
|
||||
constexpr auto operator""_yd(unsigned long long l) { return quantity<yard, std::int64_t>(l); }
|
||||
constexpr auto operator""_yd(long double l) { return quantity<yard, long double>(l); }
|
||||
|
||||
// ft
|
||||
constexpr auto operator""_ft(unsigned long long l) { return length<foot, std::int64_t>(l); }
|
||||
constexpr auto operator""_ft(long double l) { return length<foot, long double>(l); }
|
||||
constexpr auto operator""_ft(unsigned long long l) { return quantity<foot, std::int64_t>(l); }
|
||||
constexpr auto operator""_ft(long double l) { return quantity<foot, long double>(l); }
|
||||
|
||||
// in
|
||||
constexpr auto operator""_in(unsigned long long l) { return length<inch, std::int64_t>(l); }
|
||||
constexpr auto operator""_in(long double l) { return length<inch, long double>(l); }
|
||||
constexpr auto operator""_in(unsigned long long l) { return quantity<inch, std::int64_t>(l); }
|
||||
constexpr auto operator""_in(long double l) { return quantity<inch, long double>(l); }
|
||||
|
||||
// mi
|
||||
constexpr auto operator""_mi(unsigned long long l) { return length<mile, std::int64_t>(l); }
|
||||
constexpr auto operator""_mi(long double l) { return length<mile, long double>(l); }
|
||||
constexpr auto operator""_mi(unsigned long long l) { return quantity<mile, std::int64_t>(l); }
|
||||
constexpr auto operator""_mi(long double l) { return quantity<mile, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -33,17 +33,14 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool LuminousIntensity = Quantity<T> && std::Same<typename T::dimension, dimension_luminous_intensity>;
|
||||
|
||||
template<Unit U = struct candela, Number Rep = double>
|
||||
using luminous_intensity = quantity<dimension_luminous_intensity, U, Rep>;
|
||||
|
||||
struct candela : unit<dimension_luminous_intensity> {};
|
||||
template<> struct downcasting_traits<downcast_from<candela>> : downcast_to<candela> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// cd
|
||||
constexpr auto operator""_cd(unsigned long long l) { return luminous_intensity<candela, std::int64_t>(l); }
|
||||
constexpr auto operator""_cd(long double l) { return luminous_intensity<candela, long double>(l); }
|
||||
constexpr auto operator""_cd(unsigned long long l) { return quantity<candela, std::int64_t>(l); }
|
||||
constexpr auto operator""_cd(long double l) { return quantity<candela, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Mass = Quantity<T> && std::Same<typename T::dimension, dimension_mass>;
|
||||
|
||||
template<Unit U = class kilogram, Number Rep = double>
|
||||
using mass = quantity<dimension_mass, U, Rep>;
|
||||
|
||||
struct gram : unit<dimension_mass, ratio<1, 1000>> {};
|
||||
template<> struct downcasting_traits<downcast_from<gram>> : downcast_to<gram> {};
|
||||
|
||||
@@ -45,12 +42,12 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// g
|
||||
constexpr auto operator""_g(unsigned long long l) { return mass<gram, std::int64_t>(l); }
|
||||
constexpr auto operator""_g(long double l) { return mass<gram, long double>(l); }
|
||||
constexpr auto operator""_g(unsigned long long l) { return quantity<gram, std::int64_t>(l); }
|
||||
constexpr auto operator""_g(long double l) { return quantity<gram, long double>(l); }
|
||||
|
||||
// kg
|
||||
constexpr auto operator""_kg(unsigned long long l) { return mass<kilogram, std::int64_t>(l); }
|
||||
constexpr auto operator""_kg(long double l) { return mass<kilogram, long double>(l); }
|
||||
constexpr auto operator""_kg(unsigned long long l) { return quantity<kilogram, std::int64_t>(l); }
|
||||
constexpr auto operator""_kg(long double l) { return quantity<kilogram, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -45,14 +45,13 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Scalar = Number<T> && !Quantity<T>;
|
||||
|
||||
template<Dimension D, Unit U, Scalar Rep>
|
||||
requires std::Same<D, typename U::dimension>
|
||||
template<Unit U, Scalar Rep>
|
||||
class quantity;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<Dimension D, Unit U, Scalar Rep>
|
||||
inline constexpr bool is_quantity<quantity<D, U, Rep>> = true;
|
||||
template<Unit U, Scalar Rep>
|
||||
inline constexpr bool is_quantity<quantity<U, Rep>> = true;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -60,14 +59,15 @@ namespace units {
|
||||
template<Quantity Q1, Quantity Q2, Scalar Rep>
|
||||
struct common_quantity;
|
||||
|
||||
template<Dimension D, Unit U, Scalar Rep1, Scalar Rep2, Scalar Rep>
|
||||
struct common_quantity<quantity<D, U, Rep1>, quantity<D, U, Rep2>, Rep> {
|
||||
using type = quantity<D, U, Rep>;
|
||||
template<Unit U, Scalar Rep1, Scalar Rep2, Scalar Rep>
|
||||
struct common_quantity<quantity<U, Rep1>, quantity<U, Rep2>, Rep> {
|
||||
using type = quantity<U, Rep>;
|
||||
};
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2, Scalar Rep>
|
||||
struct common_quantity<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, Rep> {
|
||||
using type = quantity<D, downcasting_traits_t<unit<D, common_ratio<typename U1::ratio, typename U2::ratio>>>, Rep>;
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2, Scalar Rep>
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
struct common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, Rep> {
|
||||
using type = quantity<downcasting_traits_t<unit<typename U1::dimension, common_ratio<typename U1::ratio, typename U2::ratio>>>, Rep>;
|
||||
};
|
||||
|
||||
template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
|
||||
@@ -121,9 +121,9 @@ namespace units {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity To, Dimension D, Unit U, Scalar Rep>
|
||||
requires std::Same<typename To::dimension, D>
|
||||
constexpr To quantity_cast(const quantity<D, U, Rep>& q)
|
||||
template<Quantity To, Unit U, Scalar Rep>
|
||||
requires std::Same<typename To::dimension, typename U::dimension>
|
||||
constexpr To quantity_cast(const quantity<U, Rep>& q)
|
||||
{
|
||||
using c_ratio = ratio_divide<typename U::ratio, typename To::unit::ratio>;
|
||||
using c_rep = std::common_type_t<typename To::rep, Rep, intmax_t>;
|
||||
@@ -143,15 +143,14 @@ namespace units {
|
||||
|
||||
// quantity
|
||||
|
||||
template<Dimension D, Unit U, Scalar Rep>
|
||||
requires std::Same<D, typename U::dimension>
|
||||
template<Unit U, Scalar Rep = double>
|
||||
class quantity {
|
||||
Rep value_;
|
||||
|
||||
public:
|
||||
using dimension = D;
|
||||
using unit = U;
|
||||
using rep = Rep;
|
||||
using dimension = U::dimension;
|
||||
|
||||
static_assert(!Quantity<Rep>, "rep cannot be a quantity");
|
||||
|
||||
@@ -238,163 +237,173 @@ namespace units {
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator+(const quantity<D, U1, Rep1>& lhs,
|
||||
const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator+(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
using common_rep = decltype(lhs.count() + rhs.count());
|
||||
using ret = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, common_rep>;
|
||||
using ret = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
||||
return ret(ret(lhs).count() + ret(rhs).count());
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator-(const quantity<D, U1, Rep1>& lhs,
|
||||
const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator-(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
using common_rep = decltype(lhs.count() - rhs.count());
|
||||
using ret = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, common_rep>;
|
||||
using ret = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
||||
return ret(ret(lhs).count() - ret(rhs).count());
|
||||
}
|
||||
|
||||
// template<Dimension D, Unit U, Scalar Rep1, Scalar Rep2>
|
||||
template<typename D, typename U, typename Rep1, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<D, U, Rep1>& q,
|
||||
// template<Unit U, Scalar Rep1, Scalar Rep2>
|
||||
template<typename U, typename Rep1, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<U, Rep1>& q,
|
||||
const Rep2& v)
|
||||
requires (!Quantity<Rep2>)
|
||||
{
|
||||
using common_rep = decltype(q.count()* v);
|
||||
using ret = quantity<D, U, common_rep>;
|
||||
using ret = quantity<U, common_rep>;
|
||||
return ret(ret(q).count() * v);
|
||||
}
|
||||
|
||||
//template<Scalar Rep1, Dimension D, Unit U, Scalar Rep2>
|
||||
template<typename Rep1, typename D, typename U, typename Rep2>
|
||||
//template<Scalar Rep1, Unit U, Scalar Rep2>
|
||||
template<typename Rep1, typename U, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const Rep1& v,
|
||||
const quantity<D, U, Rep2>& q)
|
||||
const quantity<U, Rep2>& q)
|
||||
requires (!Quantity<Rep1>)
|
||||
{
|
||||
return q * v;
|
||||
}
|
||||
|
||||
template<Dimension D1, Unit U1, Scalar Rep1, Dimension D2, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)
|
||||
{
|
||||
using dim = dimension_multiply_t<D1, D2>;
|
||||
using dim = dimension_multiply_t<typename U1::dimension, typename U2::dimension>;
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
using ret = quantity<dim, downcasting_traits_t<unit<dim, ratio_multiply<typename U1::ratio, typename U2::ratio>>>, common_rep>;
|
||||
using ret = quantity<downcasting_traits_t<unit<dim, ratio_multiply<typename U1::ratio, typename U2::ratio>>>, common_rep>;
|
||||
return ret(lhs.count() * rhs.count());
|
||||
}
|
||||
|
||||
// template<Scalar Rep1, Dimension D, Unit U, Scalar Rep2>
|
||||
template<typename Rep1, typename D, typename U, typename Rep2>
|
||||
// template<Scalar Rep1, Unit U, Scalar Rep2>
|
||||
template<typename Rep1, typename U, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const Rep1& v,
|
||||
const quantity<D, U, Rep2>& q)
|
||||
const quantity<U, Rep2>& q)
|
||||
requires (!Quantity<Rep1>)
|
||||
{
|
||||
Expects(q != std::remove_cvref_t<decltype(q)>(0));
|
||||
|
||||
using dim = dim_invert_t<D>;
|
||||
using dim = dim_invert_t<typename U::dimension>;
|
||||
using common_rep = decltype(v / q.count());
|
||||
using ret = quantity<dim, downcasting_traits_t<unit<dim, ratio<U::ratio::den, U::ratio::num>>>, common_rep>;
|
||||
using den = quantity<D, U, common_rep>;
|
||||
using ret = quantity<downcasting_traits_t<unit<dim, ratio<U::ratio::den, U::ratio::num>>>, common_rep>;
|
||||
using den = quantity<U, common_rep>;
|
||||
return ret(v / den(q).count());
|
||||
}
|
||||
|
||||
// template<Dimension D, Unit U, Scalar Rep1, Scalar Rep2>
|
||||
template<typename D, typename U, typename Rep1, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const quantity<D, U, Rep1>& q,
|
||||
// template<Unit U, Scalar Rep1, Scalar Rep2>
|
||||
template<typename U, typename Rep1, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const quantity<U, Rep1>& q,
|
||||
const Rep2& v)
|
||||
requires (!Quantity<Rep2>)
|
||||
{
|
||||
Expects(v != Rep2{0});
|
||||
|
||||
using common_rep = decltype(q.count() / v);
|
||||
using ret = quantity<D, U, common_rep>;
|
||||
using ret = quantity<U, common_rep>;
|
||||
return ret(ret(q).count() / v);
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Scalar operator/(const quantity<D, U1, Rep1>& lhs,
|
||||
const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Scalar operator/(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
||||
|
||||
using common_rep = decltype(lhs.count() / rhs.count());
|
||||
using cq = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, common_rep>;
|
||||
using cq = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
||||
return cq(lhs).count() / cq(rhs).count();
|
||||
}
|
||||
|
||||
template<Dimension D1, Unit U1, Scalar Rep1, Dimension D2, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs)
|
||||
requires treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires (!std::Same<typename U1::dimension, typename U2::dimension>) &&
|
||||
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||
{
|
||||
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
||||
|
||||
using common_rep = decltype(lhs.count() / rhs.count());
|
||||
using dim = dimension_divide_t<D1, D2>;
|
||||
using ret = quantity<dim, downcasting_traits_t<unit<dim, ratio_divide<typename U1::ratio, typename U2::ratio>>>, common_rep>;
|
||||
using dim = dimension_divide_t<typename U1::dimension, typename U2::dimension>;
|
||||
using ret = quantity<downcasting_traits_t<unit<dim, ratio_divide<typename U1::ratio, typename U2::ratio>>>, common_rep>;
|
||||
return ret(lhs.count() / rhs.count());
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U, Scalar Rep1, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator%(const quantity<D, U, Rep1>& q,
|
||||
template<Unit U, Scalar Rep1, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator%(const quantity<U, Rep1>& q,
|
||||
const Rep2& v)
|
||||
{
|
||||
using common_rep = decltype(q.count() % v);
|
||||
using ret = quantity<D, U, common_rep>;
|
||||
using ret = quantity<U, common_rep>;
|
||||
return ret(ret(q).count() % v);
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator%(const quantity<D, U1, Rep1>& lhs,
|
||||
const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator%(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
{
|
||||
using common_rep = decltype(lhs.count() % rhs.count());
|
||||
using ret = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, common_rep>;
|
||||
using ret = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
||||
return ret(ret(lhs).count() % ret(rhs).count());
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator==(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator==(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
using ct = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>>;
|
||||
using ct = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>>;
|
||||
return ct(lhs).count() == ct(rhs).count();
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator!=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator!=(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator<(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator<(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
using ct = common_quantity_t<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>>;
|
||||
using ct = common_quantity_t<quantity<U1, Rep1>, quantity<U2, Rep2>>;
|
||||
return ct(lhs).count() < ct(rhs).count();
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator<=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator<=(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator>(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator>(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
template<Dimension D, Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator>=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr bool operator>=(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
@@ -33,17 +33,14 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Substance = Quantity<T> && std::Same<typename T::dimension, dimension_substance>;
|
||||
|
||||
template<Unit U = struct mole, Number Rep = double>
|
||||
using substance = quantity<dimension_substance, U, Rep>;
|
||||
|
||||
struct mole : unit<dimension_substance> {};
|
||||
template<> struct downcasting_traits<downcast_from<mole>> : downcast_to<mole> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// mol
|
||||
constexpr auto operator""_mol(unsigned long long l) { return substance<mole, std::int64_t>(l); }
|
||||
constexpr auto operator""_mol(long double l) { return substance<mole, long double>(l); }
|
||||
constexpr auto operator""_mol(unsigned long long l) { return quantity<mole, std::int64_t>(l); }
|
||||
constexpr auto operator""_mol(long double l) { return quantity<mole, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -33,17 +33,14 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool ThermodynamicTemperature = Quantity<T> && std::Same<typename T::dimension, dimension_temperature>;
|
||||
|
||||
template<Unit U = struct kelvin, Number Rep = double>
|
||||
using temperature = quantity<dimension_temperature, U, Rep>;
|
||||
|
||||
struct kelvin : unit<dimension_temperature> {};
|
||||
template<> struct downcasting_traits<downcast_from<kelvin>> : downcast_to<kelvin> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// K
|
||||
constexpr auto operator""_K(unsigned long long l) { return temperature<kelvin, std::int64_t>(l); }
|
||||
constexpr auto operator""_K(long double l) { return temperature<kelvin, long double>(l); }
|
||||
constexpr auto operator""_K(unsigned long long l) { return quantity<kelvin, std::int64_t>(l); }
|
||||
constexpr auto operator""_K(long double l) { return quantity<kelvin, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
+12
-15
@@ -33,9 +33,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Time = Quantity<T> && std::Same<typename T::dimension, dimension_time>;
|
||||
|
||||
template<Unit U = struct second, Number Rep = double>
|
||||
using time = quantity<dimension_time, U, Rep>;
|
||||
|
||||
struct second : unit<dimension_time> {};
|
||||
template<> struct downcasting_traits<downcast_from<second>> : downcast_to<second> {};
|
||||
|
||||
@@ -57,28 +54,28 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// ns
|
||||
constexpr auto operator""_ns(unsigned long long l) { return time<nanosecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ns(long double l) { return time<nanosecond, long double>(l); }
|
||||
constexpr auto operator""_ns(unsigned long long l) { return quantity<nanosecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ns(long double l) { return quantity<nanosecond, long double>(l); }
|
||||
|
||||
// us
|
||||
constexpr auto operator""_us(unsigned long long l) { return time<microsecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_us(long double l) { return time<microsecond, long double>(l); }
|
||||
constexpr auto operator""_us(unsigned long long l) { return quantity<microsecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_us(long double l) { return quantity<microsecond, long double>(l); }
|
||||
|
||||
// ms
|
||||
constexpr auto operator""_ms(unsigned long long l) { return time<millisecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ms(long double l) { return time<millisecond, long double>(l); }
|
||||
constexpr auto operator""_ms(unsigned long long l) { return quantity<millisecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ms(long double l) { return quantity<millisecond, long double>(l); }
|
||||
|
||||
// s
|
||||
constexpr auto operator""_s(unsigned long long l) { return time<second, std::int64_t>(l); }
|
||||
constexpr auto operator""_s(long double l) { return time<second, long double>(l); }
|
||||
constexpr auto operator""_s(unsigned long long l) { return quantity<second, std::int64_t>(l); }
|
||||
constexpr auto operator""_s(long double l) { return quantity<second, long double>(l); }
|
||||
|
||||
// min
|
||||
constexpr auto operator""_min(unsigned long long l) { return time<minute, std::int64_t>(l); }
|
||||
constexpr auto operator""_min(long double l) { return time<minute, long double>(l); }
|
||||
constexpr auto operator""_min(unsigned long long l) { return quantity<minute, std::int64_t>(l); }
|
||||
constexpr auto operator""_min(long double l) { return quantity<minute, long double>(l); }
|
||||
|
||||
// h
|
||||
constexpr auto operator""_h(unsigned long long l) { return time<hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_h(long double l) { return time<hour, long double>(l); }
|
||||
constexpr auto operator""_h(unsigned long long l) { return quantity<hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_h(long double l) { return quantity<hour, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace units {
|
||||
template<typename T>
|
||||
concept bool Velocity = Quantity<T> && std::Same<typename T::dimension, dimension_velocity>;
|
||||
|
||||
template<Unit U = struct meter_per_second, Number Rep = double>
|
||||
using velocity = quantity<dimension_velocity, U, Rep>;
|
||||
|
||||
struct meter_per_second : derived_unit<dimension_velocity, meter, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter_per_second>> : downcast_to<meter_per_second> {};
|
||||
|
||||
@@ -48,16 +45,16 @@ namespace units {
|
||||
inline namespace literals {
|
||||
|
||||
// mps
|
||||
constexpr auto operator""_mps(unsigned long long l) { return velocity<meter_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return velocity<meter_per_second, long double>(l); }
|
||||
constexpr auto operator""_mps(unsigned long long l) { return quantity<meter_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return quantity<meter_per_second, long double>(l); }
|
||||
|
||||
// kmph
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return velocity<kilometer_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return velocity<kilometer_per_hour, long double>(l); }
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return quantity<kilometer_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return quantity<kilometer_per_hour, long double>(l); }
|
||||
|
||||
// mph
|
||||
constexpr auto operator""_mph(unsigned long long l) { return velocity<mile_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_mph(long double l) { return velocity<mile_per_hour, long double>(l); }
|
||||
constexpr auto operator""_mph(unsigned long long l) { return quantity<mile_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_mph(long double l) { return quantity<mile_per_hour, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
Reference in new issue
Block a user