Specialize common_type to satisfy comparison concepts (resolves #113)

This commit is contained in:
Mateusz Pusz
2020-05-28 20:19:05 +02:00
parent ed9f51c75b
commit 86b9177816
2 changed files with 20 additions and 0 deletions

View File

@@ -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>;
};
}

View File

@@ -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>);