forked from mpusz/mp-units
quantity_cast_impl refactored to use compile time branching rather than concepts
This commit is contained in:
@@ -93,18 +93,16 @@ namespace units {
|
|||||||
template<typename To, typename CR, typename CRep, bool NumIsOne = false, bool DenIsOne = false>
|
template<typename To, typename CR, typename CRep, bool NumIsOne = false, bool DenIsOne = false>
|
||||||
struct quantity_cast_impl {
|
struct quantity_cast_impl {
|
||||||
template<typename Q>
|
template<typename Q>
|
||||||
requires treat_as_floating_point<CRep>
|
|
||||||
static constexpr To cast(const Q& q)
|
static constexpr To cast(const Q& q)
|
||||||
{
|
{
|
||||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * (static_cast<CRep>(CR::num) /
|
if constexpr(treat_as_floating_point<CRep>) {
|
||||||
static_cast<CRep>(CR::den))));
|
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * (static_cast<CRep>(CR::num) /
|
||||||
}
|
static_cast<CRep>(CR::den))));
|
||||||
template<typename Q>
|
}
|
||||||
requires !treat_as_floating_point<CRep>
|
else {
|
||||||
static constexpr To cast(const Q& q)
|
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) /
|
||||||
{
|
static_cast<CRep>(CR::den)));
|
||||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) /
|
}
|
||||||
static_cast<CRep>(CR::den)));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,16 +118,14 @@ namespace units {
|
|||||||
template<typename To, typename CR, typename CRep>
|
template<typename To, typename CR, typename CRep>
|
||||||
struct quantity_cast_impl<To, CR, CRep, true, false> {
|
struct quantity_cast_impl<To, CR, CRep, true, false> {
|
||||||
template<Quantity Q>
|
template<Quantity Q>
|
||||||
requires treat_as_floating_point<CRep>
|
|
||||||
static constexpr To cast(const Q& q)
|
static constexpr To cast(const Q& q)
|
||||||
{
|
{
|
||||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * (CRep{1} / static_cast<CRep>(CR::den))));
|
if constexpr(treat_as_floating_point<CRep>) {
|
||||||
}
|
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * (CRep{1} / static_cast<CRep>(CR::den))));
|
||||||
template<Quantity Q>
|
}
|
||||||
requires !treat_as_floating_point<CRep>
|
else {
|
||||||
static constexpr To cast(const Q& q)
|
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) / static_cast<CRep>(CR::den)));
|
||||||
{
|
}
|
||||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) / static_cast<CRep>(CR::den)));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user