-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathquantity.patch
More file actions
111 lines (96 loc) · 4.32 KB
/
quantity.patch
File metadata and controls
111 lines (96 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
diff --git a/include/quantity.h b/include/quantity.h
index 1724837..b5bdd4f 100644
--- a/include/quantity.h
+++ b/include/quantity.h
@@ -25,6 +25,7 @@
#include "common_ratio.h"
#include "unit.h"
#include <limits>
+#include <type_traits>
// Requires
@@ -149,28 +150,20 @@ namespace units {
[[nodiscard]] constexpr quantity operator+() const { return *this; }
[[nodiscard]] constexpr quantity operator-() const { return quantity(-count()); }
- template<typename T = Rep,
- Requires<!treat_as_floating_point<T>> = true>
constexpr quantity& operator++()
{
++value_;
return *this;
}
- template<typename T = Rep,
- Requires<!treat_as_floating_point<T>> = true>
[[nodiscard]] constexpr quantity operator++(int) { return quantity(value_++); }
- template<typename T = Rep,
- Requires<!treat_as_floating_point<T>> = true>
constexpr quantity& operator--()
{
--value_;
return *this;
}
- template<typename T = Rep,
- Requires<!treat_as_floating_point<T>> = true>
[[nodiscard]] constexpr quantity operator--(int) { return quantity(value_--); }
constexpr quantity& operator+=(const quantity& q)
@@ -210,7 +203,7 @@ namespace units {
template<typename Rep2>
[[nodiscard]] friend constexpr auto operator+(const quantity& lhs, const quantity<Unit, Rep2>& rhs)
- -> quantity<Unit, decltype(lhs.count() + rhs.count())>
+ -> quantity<Unit, decltype(std::declval<Rep>() + std::declval<Rep2>())>
{
using ret = quantity<Unit, decltype(lhs.count() + rhs.count())>;
return ret(lhs.count() + rhs.count());
@@ -218,7 +211,7 @@ namespace units {
template<typename Rep2>
[[nodiscard]] friend constexpr auto operator-(const quantity& lhs, const quantity<Unit, Rep2>& rhs)
- -> quantity<Unit, decltype(lhs.count() - rhs.count())>
+ -> quantity<Unit, decltype(std::declval<Rep>() - std::declval<Rep2>())>
{
using ret = quantity<Unit, decltype(lhs.count() - rhs.count())>;
return ret(lhs.count() - rhs.count());
@@ -226,13 +219,15 @@ namespace units {
template<typename Rep2,
Requires<!is_quantity<Rep2>> = true>
- [[nodiscard]] friend constexpr auto operator*(const quantity& q, const Rep2& v) -> quantity<Unit, decltype(q.count() * v)>
+ [[nodiscard]] friend constexpr auto operator*(const quantity& q, const Rep2& v)
+ -> quantity<Unit, decltype(std::declval<Rep>() * std::declval<Rep2>())>
{
using ret = quantity<Unit, decltype(q.count() * v)>;
return ret(q.count() * v);
}
- template<typename Rep2>
+ template<typename Rep2,
+ Requires<!is_quantity<Rep2>> = true>
[[nodiscard]] friend constexpr auto operator*(const Rep2& v, const quantity& q) -> decltype(q * v)
{
return q * v;
@@ -240,7 +235,8 @@ namespace units {
template<typename Rep2,
Requires<!is_quantity<Rep2>> = true>
- [[nodiscard]] friend constexpr auto operator/(const quantity& q, const Rep2& v) -> quantity<Unit, decltype(q.count() / v)>
+ [[nodiscard]] friend constexpr auto operator/(const quantity& q, const Rep2& v)
+ -> quantity<Unit, decltype(std::declval<Rep>() / std::declval<Rep2>())>
{
using ret = quantity<Unit, decltype(q.count() / v)>;
return ret(q.count() / v);
@@ -248,12 +244,12 @@ namespace units {
template<typename Rep2>
[[nodiscard]] friend constexpr auto operator/(const quantity& lhs, const quantity<Unit, Rep2>& rhs)
- -> decltype(lhs.count() / rhs.count())
+ -> decltype(std::declval<Rep>() / std::declval<Rep2>())
{
return lhs.count() / rhs.count();
}
- template<typename T = Rep, typename Rep2,
+ template<typename Rep2, typename T = Rep,
Requires<!is_quantity<Rep2> &&
!treat_as_floating_point<T> &&
!treat_as_floating_point<Rep2>> = true>
@@ -262,7 +258,7 @@ namespace units {
return quantity(q.count() % v);
}
- template<typename T = Rep, typename Rep2,
+ template<typename Rep2, typename T = Rep,
Requires<!treat_as_floating_point<T> &&
!treat_as_floating_point<Rep2>> = true>
[[nodiscard]] friend constexpr quantity operator%(const quantity& lhs, const quantity<Unit, Rep2>& rhs)