Small quantity formatting cleanup with clang-format

This commit is contained in:
Mateusz Pusz
2019-10-15 11:29:25 +02:00
parent 527927e905
commit 2bcc5fa4e5

View File

@@ -22,8 +22,8 @@
#pragma once #pragma once
#include <units/unit.h>
#include <units/bits/concepts.h> #include <units/bits/concepts.h>
#include <units/unit.h>
#include <limits> #include <limits>
namespace units { namespace units {
@@ -36,7 +36,7 @@ namespace units {
// partial specialization below after the first quantity forward declaration // partial specialization below after the first quantity forward declaration
} } // namespace detail
template<typename T> template<typename T>
concept Quantity = detail::is_quantity<T>; concept Quantity = detail::is_quantity<T>;
@@ -73,10 +73,12 @@ namespace units {
template<typename U1, typename Rep1, typename U2, typename Rep2, typename Rep> template<typename U1, typename Rep1, typename U2, typename Rep2, typename Rep>
requires same_dim<typename U1::dimension, typename U2::dimension> requires same_dim<typename U1::dimension, typename U2::dimension>
struct common_quantity_impl<quantity<U1, Rep1>, quantity<U2, Rep2>, Rep> { struct common_quantity_impl<quantity<U1, Rep1>, quantity<U2, Rep2>, Rep> {
using type = quantity<downcast_target<unit<typename U1::dimension, common_ratio<typename U1::ratio, typename U2::ratio>>>, Rep>; using type =
quantity<downcast_target<unit<typename U1::dimension, common_ratio<typename U1::ratio, typename U2::ratio>>>,
Rep>;
}; };
} } // namespace detail
template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>> template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type; using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type;
@@ -96,12 +98,12 @@ namespace units {
static constexpr To cast(const Q& q) static constexpr To cast(const Q& q)
{ {
if constexpr(treat_as_floating_point<CRep>) { if constexpr(treat_as_floating_point<CRep>) {
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * (static_cast<CRep>(CR::num) / return To(static_cast<To::rep>(static_cast<CRep>(q.count()) *
static_cast<CRep>(CR::den)))); (static_cast<CRep>(CR::num) / static_cast<CRep>(CR::den))));
} }
else { else {
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) / return To(
static_cast<CRep>(CR::den))); static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) / static_cast<CRep>(CR::den)));
} }
} }
}; };
@@ -168,7 +170,6 @@ namespace units {
return quantity_cast<quantity<U, ToRep>>(q); return quantity_cast<quantity<U, ToRep>>(q);
} }
// quantity_values // quantity_values
template<Scalar Rep> template<Scalar Rep>
@@ -276,10 +277,8 @@ namespace units {
} }
}; };
// clang-format off
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator+(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Quantity operator+(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension> requires same_dim<typename U1::dimension, typename U2::dimension>
{ {
using common_rep = decltype(lhs.count() + rhs.count()); using common_rep = decltype(lhs.count() + rhs.count());
@@ -288,8 +287,7 @@ namespace units {
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator-(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Quantity operator-(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension> requires same_dim<typename U1::dimension, typename U2::dimension>
{ {
using common_rep = decltype(lhs.count() - rhs.count()); using common_rep = decltype(lhs.count() - rhs.count());
@@ -298,8 +296,7 @@ namespace units {
} }
template<typename U, typename Rep1, Scalar Rep2> template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator*(const quantity<U, Rep1>& q, [[nodiscard]] constexpr Quantity operator*(const quantity<U, Rep1>& q, const Rep2& v)
const Rep2& v)
requires (!Quantity<Rep2>) requires (!Quantity<Rep2>)
{ {
using common_rep = decltype(q.count() * v); using common_rep = decltype(q.count() * v);
@@ -308,16 +305,14 @@ namespace units {
} }
template<Scalar Rep1, typename U, typename Rep2> template<Scalar Rep1, typename U, typename Rep2>
[[nodiscard]] constexpr Quantity operator*(const Rep1& v, [[nodiscard]] constexpr Quantity operator*(const Rep1& v, const quantity<U, Rep2>& q)
const quantity<U, Rep2>& q)
requires (!Quantity<Rep1>) requires (!Quantity<Rep1>)
{ {
return q * v; return q * v;
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Scalar operator*(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Scalar operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, dim_invert<typename U2::dimension>> requires same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>
{ {
using common_rep = decltype(lhs.count() * rhs.count()); using common_rep = decltype(lhs.count() * rhs.count());
@@ -326,8 +321,7 @@ namespace units {
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires (!same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>) && requires (!same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>) &&
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> || (treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)) (std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
@@ -339,8 +333,7 @@ namespace units {
} }
template<Scalar Rep1, typename U, typename Rep2> template<Scalar Rep1, typename U, typename Rep2>
[[nodiscard]] constexpr Quantity operator/(const Rep1& v, [[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity<U, Rep2>& q)
const quantity<U, Rep2>& q)
requires (!Quantity<Rep1>) requires (!Quantity<Rep1>)
{ {
Expects(q != std::remove_cvref_t<decltype(q)>(0)); Expects(q != std::remove_cvref_t<decltype(q)>(0));
@@ -353,8 +346,7 @@ namespace units {
} }
template<typename U, typename Rep1, Scalar Rep2> template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator/(const quantity<U, Rep1>& q, [[nodiscard]] constexpr Quantity operator/(const quantity<U, Rep1>& q, const Rep2& v)
const Rep2& v)
requires (!Quantity<Rep2>) requires (!Quantity<Rep2>)
{ {
Expects(v != Rep2{0}); Expects(v != Rep2{0});
@@ -365,8 +357,7 @@ namespace units {
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Scalar operator/(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Scalar operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension> requires same_dim<typename U1::dimension, typename U2::dimension>
{ {
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0)); Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
@@ -377,8 +368,7 @@ namespace units {
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator/(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Quantity operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
requires (!same_dim<typename U1::dimension, typename U2::dimension>) && requires (!same_dim<typename U1::dimension, typename U2::dimension>) &&
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> || (treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1)) (ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
@@ -392,8 +382,7 @@ namespace units {
} }
template<typename U, typename Rep1, Scalar Rep2> template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator%(const quantity<U, Rep1>& q, [[nodiscard]] constexpr Quantity operator%(const quantity<U, Rep1>& q, const Rep2& v)
const Rep2& v)
{ {
using common_rep = decltype(q.count() % v); using common_rep = decltype(q.count() % v);
using ret = quantity<U, common_rep>; using ret = quantity<U, common_rep>;
@@ -401,16 +390,13 @@ namespace units {
} }
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator%(const quantity<U1, Rep1>& lhs, [[nodiscard]] constexpr Quantity operator%(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
const quantity<U2, Rep2>& rhs)
{ {
using common_rep = decltype(lhs.count() % rhs.count()); using common_rep = decltype(lhs.count() % rhs.count());
using ret = common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>; using ret = common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
return ret(ret(lhs).count() % ret(rhs).count()); return ret(ret(lhs).count() % ret(rhs).count());
} }
// clang-format on
template<typename U1, typename Rep1, typename U2, typename Rep2> template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr bool operator==(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs) [[nodiscard]] constexpr bool operator==(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension> requires same_dim<typename U1::dimension, typename U2::dimension>