From 4ba818bb7819825e7bd1bfa21a70a20dec6cd863 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 8 Oct 2019 21:20:06 +0200 Subject: [PATCH] quantity_cast_impl refactored to use compile time branching rather than concepts --- src/include/units/quantity.h | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index b0ea1def..7cd558ad 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -93,18 +93,16 @@ namespace units { template struct quantity_cast_impl { template - requires treat_as_floating_point static constexpr To cast(const Q& q) { - return To(static_cast(static_cast(q.count()) * (static_cast(CR::num) / - static_cast(CR::den)))); - } - template - requires !treat_as_floating_point - static constexpr To cast(const Q& q) - { - return To(static_cast(static_cast(q.count()) * static_cast(CR::num) / - static_cast(CR::den))); + if constexpr(treat_as_floating_point) { + return To(static_cast(static_cast(q.count()) * (static_cast(CR::num) / + static_cast(CR::den)))); + } + else { + return To(static_cast(static_cast(q.count()) * static_cast(CR::num) / + static_cast(CR::den))); + } } }; @@ -120,16 +118,14 @@ namespace units { template struct quantity_cast_impl { template - requires treat_as_floating_point static constexpr To cast(const Q& q) { - return To(static_cast(static_cast(q.count()) * (CRep{1} / static_cast(CR::den)))); - } - template - requires !treat_as_floating_point - static constexpr To cast(const Q& q) - { - return To(static_cast(static_cast(q.count()) / static_cast(CR::den))); + if constexpr(treat_as_floating_point) { + return To(static_cast(static_cast(q.count()) * (CRep{1} / static_cast(CR::den)))); + } + else { + return To(static_cast(static_cast(q.count()) / static_cast(CR::den))); + } } };