File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 3
3
#include < utility>
4
4
#include < iostream>
5
5
#include < memory>
6
+ #include < type_traits>
6
7
7
8
#if __cplusplus > 201703L
8
9
#include < compare>
@@ -100,6 +101,20 @@ class Rational
100
101
};
101
102
102
103
104
+ template <typename T>
105
+ auto operator / (T num, Rational value) ->
106
+ std::enable_if_t <std::is_floating_point_v<T> || std::is_integral_v<T>, Rational>
107
+ {
108
+ return Rational{num, 1 } / value;
109
+ }
110
+
111
+ template <typename T>
112
+ auto operator / (Rational value, T num) ->
113
+ std::enable_if_t <std::is_floating_point_v<T> || std::is_integral_v<T>, Rational>
114
+ {
115
+ return value / Rational{num, 1 };
116
+ }
117
+
103
118
inline std::ostream& operator << (std::ostream &stream, const Rational &value)
104
119
{
105
120
stream << value.getNumerator () << ' /' << value.getDenominator ();
You can’t perform that action at this time.
0 commit comments