mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 04:14:27 +02:00
Specialize common_type to satisfy comparison concepts (resolves #113)
This commit is contained in:
@@ -64,3 +64,13 @@ template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::
|
||||
using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type;
|
||||
|
||||
} // namespace units
|
||||
|
||||
namespace std {
|
||||
|
||||
template<units::Quantity Q1, units::Quantity Q2>
|
||||
requires units::equivalent_dim<typename Q1::dimension, typename Q2::dimension>
|
||||
struct common_type<Q1, Q2> {
|
||||
using type = units::common_quantity<Q1, Q2>;
|
||||
};
|
||||
|
||||
}
|
@@ -25,6 +25,7 @@
|
||||
#include "units/physical/si/frequency.h"
|
||||
#include "units/physical/si/speed.h"
|
||||
#include "units/physical/si/volume.h"
|
||||
#include "units/physical/us/length.h"
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
@@ -222,6 +223,15 @@ static_assert(
|
||||
static_assert(std::is_same_v<common_quantity<length<kilometre, long long>, length<millimetre, double>>,
|
||||
length<millimetre, double>>);
|
||||
|
||||
// common_type
|
||||
|
||||
using namespace units::physical::us::literals;
|
||||
|
||||
static_assert(std::equality_comparable<decltype(1q_m)>);
|
||||
static_assert(std::equality_comparable_with<decltype(1q_m), decltype(1q_cm)>);
|
||||
static_assert(0q_m == 0q_ft_us);
|
||||
static_assert(std::equality_comparable_with<decltype(1q_m), decltype(1q_ft_us)>);
|
||||
|
||||
// quantity_cast
|
||||
|
||||
static_assert(std::is_same_v<decltype(quantity_cast<scaled_unit<ratio<1>, metre>>(2q_km))::unit, metre>);
|
||||
|
Reference in New Issue
Block a user