From 2bcc5fa4e555e9d034498fcb78f01845262b7be4 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 15 Oct 2019 11:29:25 +0200 Subject: [PATCH] Small quantity formatting cleanup with clang-format --- src/include/units/quantity.h | 118 +++++++++++++++-------------------- 1 file changed, 52 insertions(+), 66 deletions(-) diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index b38de83b..0345e97c 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -22,8 +22,8 @@ #pragma once -#include #include +#include #include namespace units { @@ -36,7 +36,7 @@ namespace units { // partial specialization below after the first quantity forward declaration - } + } // namespace detail template concept Quantity = detail::is_quantity; @@ -71,19 +71,21 @@ namespace units { }; template - requires same_dim + requires same_dim struct common_quantity_impl, quantity, Rep> { - using type = quantity>>, Rep>; + using type = + quantity>>, + Rep>; }; - } + } // namespace detail template> using common_quantity = detail::common_quantity_impl::type; // treat_as_floating_point - template // todo Conceptify that + template // todo Conceptify that inline constexpr bool treat_as_floating_point = std::is_floating_point_v; // quantity_cast @@ -96,12 +98,12 @@ namespace units { static constexpr To cast(const Q& q) { if constexpr(treat_as_floating_point) { - return To(static_cast(static_cast(q.count()) * (static_cast(CR::num) / - static_cast(CR::den)))); + 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))); + return To( + static_cast(static_cast(q.count()) * static_cast(CR::num) / static_cast(CR::den))); } } }; @@ -142,7 +144,7 @@ namespace units { template [[nodiscard]] constexpr To quantity_cast(const quantity& q) - requires same_dim + requires same_dim { using c_ratio = ratio_divide; using c_rep = std::common_type_t; @@ -161,14 +163,13 @@ namespace units { { return quantity_cast>(q); } - + template [[nodiscard]] constexpr quantity quantity_cast(const quantity& q) { return quantity_cast>(q); } - // quantity_values template @@ -195,18 +196,18 @@ namespace units { template requires std::convertible_to && - (treat_as_floating_point || (!treat_as_floating_point)) - constexpr explicit quantity(const Rep2& r) : value_{static_cast(r)} + (treat_as_floating_point || (!treat_as_floating_point)) + constexpr explicit quantity(const Rep2& r): value_{static_cast(r)} { } template requires same_dim && - std::convertible_to && - (treat_as_floating_point || - (std::ratio_divide::den == 1 && - !treat_as_floating_point)) - constexpr quantity(const Q2& q) : value_{quantity_cast(q).count()} + std::convertible_to && + (treat_as_floating_point || + (std::ratio_divide::den == 1 && + !treat_as_floating_point)) + constexpr quantity(const Q2& q): value_{quantity_cast(q).count()} { } @@ -262,7 +263,7 @@ namespace units { template constexpr quantity& operator%=(const Rep2& rhs) - requires (!treat_as_floating_point && !treat_as_floating_point) + requires (!treat_as_floating_point && !treat_as_floating_point) { value_ %= rhs; return *this; @@ -276,11 +277,9 @@ namespace units { } }; - // clang-format off template - [[nodiscard]] constexpr Quantity operator+(const quantity& lhs, - const quantity& rhs) - requires same_dim + [[nodiscard]] constexpr Quantity operator+(const quantity& lhs, const quantity& rhs) + requires same_dim { using common_rep = decltype(lhs.count() + rhs.count()); using ret = common_quantity, quantity, common_rep>; @@ -288,9 +287,8 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator-(const quantity& lhs, - const quantity& rhs) - requires same_dim + [[nodiscard]] constexpr Quantity operator-(const quantity& lhs, const quantity& rhs) + requires same_dim { using common_rep = decltype(lhs.count() - rhs.count()); using ret = common_quantity, quantity, common_rep>; @@ -298,26 +296,23 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator*(const quantity& q, - const Rep2& v) - requires (!Quantity) + [[nodiscard]] constexpr Quantity operator*(const quantity& q, const Rep2& v) + requires (!Quantity) { - using common_rep = decltype(q.count()* v); + using common_rep = decltype(q.count() * v); using ret = quantity; return ret(ret(q).count() * v); } template - [[nodiscard]] constexpr Quantity operator*(const Rep1& v, - const quantity& q) - requires (!Quantity) + [[nodiscard]] constexpr Quantity operator*(const Rep1& v, const quantity& q) + requires (!Quantity) { return q * v; } template - [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, - const quantity& rhs) + [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, const quantity& rhs) requires same_dim> { using common_rep = decltype(lhs.count() * rhs.count()); @@ -326,10 +321,9 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, - const quantity& rhs) + [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, const quantity& rhs) requires (!same_dim>) && - (treat_as_floating_point || + (treat_as_floating_point || (std::ratio_multiply::den == 1)) { using dim = dimension_multiply; @@ -339,9 +333,8 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const Rep1& v, - const quantity& q) - requires (!Quantity) + [[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity& q) + requires (!Quantity) { Expects(q != std::remove_cvref_t(0)); @@ -353,9 +346,8 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const quantity& q, - const Rep2& v) - requires (!Quantity) + [[nodiscard]] constexpr Quantity operator/(const quantity& q, const Rep2& v) + requires (!Quantity) { Expects(v != Rep2{0}); @@ -365,9 +357,8 @@ namespace units { } template - [[nodiscard]] constexpr Scalar operator/(const quantity& lhs, - const quantity& rhs) - requires same_dim + [[nodiscard]] constexpr Scalar operator/(const quantity& lhs, const quantity& rhs) + requires same_dim { Expects(rhs != std::remove_cvref_t(0)); @@ -377,11 +368,10 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const quantity& lhs, - const quantity& rhs) - requires (!same_dim) && - (treat_as_floating_point || - (ratio_divide::den == 1)) + [[nodiscard]] constexpr Quantity operator/(const quantity& lhs, const quantity& rhs) + requires (!same_dim) && + (treat_as_floating_point || + (ratio_divide::den == 1)) { Expects(rhs != std::remove_cvref_t(0)); @@ -392,8 +382,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator%(const quantity& q, - const Rep2& v) + [[nodiscard]] constexpr Quantity operator%(const quantity& q, const Rep2& v) { using common_rep = decltype(q.count() % v); using ret = quantity; @@ -401,19 +390,16 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator%(const quantity& lhs, - const quantity& rhs) + [[nodiscard]] constexpr Quantity operator%(const quantity& lhs, const quantity& rhs) { using common_rep = decltype(lhs.count() % rhs.count()); using ret = common_quantity, quantity, common_rep>; return ret(ret(lhs).count() % ret(rhs).count()); } - // clang-format on - template [[nodiscard]] constexpr bool operator==(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { using ct = common_quantity, quantity>; return ct(lhs).count() == ct(rhs).count(); @@ -421,14 +407,14 @@ namespace units { template [[nodiscard]] constexpr bool operator!=(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { return !(lhs == rhs); } template [[nodiscard]] constexpr bool operator<(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { using ct = common_quantity, quantity>; return ct(lhs).count() < ct(rhs).count(); @@ -436,21 +422,21 @@ namespace units { template [[nodiscard]] constexpr bool operator<=(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { return !(rhs < lhs); } template [[nodiscard]] constexpr bool operator>(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { return rhs < lhs; } template [[nodiscard]] constexpr bool operator>=(const quantity& lhs, const quantity& rhs) - requires same_dim + requires same_dim { return !(lhs < rhs); }