From dc85dd84b99fbd0b63d2277ef6fda3ade505987d Mon Sep 17 00:00:00 2001 From: Jan Sende <44576417+jansende@users.noreply.github.com> Date: Mon, 30 Sep 2019 00:07:16 +0200 Subject: [PATCH] Made quantity_cast more versatile - One can now change the unit type without changing the representation type. - One can now change the representation type without changing the unit type. - Had to implement std::common_type to still compile integration tests. (It implicitly converted to another representation before.) --- src/include/units/quantity.h | 12 +++++++++++- test/unit_test/test_quantity.cpp | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index ad7b08ee..ff547d47 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -135,11 +135,21 @@ namespace units { return cast::cast(q); } - template + template constexpr quantity quantity_cast(const quantity& q) { return quantity_cast>(q); } + template + constexpr quantity quantity_cast(const quantity& q) + { + return quantity_cast>(q); + } + template + constexpr quantity quantity_cast(const quantity& q) + { + return quantity_cast>(q); + } // quantity_values diff --git a/test/unit_test/test_quantity.cpp b/test/unit_test/test_quantity.cpp index e7bd28d7..fb8e88a5 100644 --- a/test/unit_test/test_quantity.cpp +++ b/test/unit_test/test_quantity.cpp @@ -62,6 +62,10 @@ namespace units { namespace std { + template + struct common_type, my_value> : common_type { + }; + template struct common_type, U> : common_type { };