@@ -34,7 +34,7 @@ class Value {
34
34
result_t <T, U>>;
35
35
36
36
template <typename T>
37
- static Value returnInt (const T& x) {
37
+ static Value returnInt (T x) {
38
38
if (std::numeric_limits<int64_t >::min () <= x &&
39
39
x <= std::numeric_limits<int64_t >::max ()) {
40
40
return Value{(int64_t )x};
@@ -44,7 +44,8 @@ class Value {
44
44
integer result = (result_upper << 64 ) + result_lower;
45
45
return Value{result};
46
46
} else {
47
- return Value{(integer)x};
47
+ static_assert (std::is_same_v<T, integer>);
48
+ return Value{std::move (x)};
48
49
}
49
50
}
50
51
template <typename T, typename U>
@@ -54,8 +55,9 @@ class Value {
54
55
throw std::invalid_argument (" value not suitable for pow" );
55
56
}
56
57
integer result = pow ((integer)(a), (unsigned )b);
57
- return returnInt (result);
58
+ return returnInt (std::move ( result) );
58
59
} else {
60
+ static_assert (std::is_same_v<T, double >);
59
61
return Value{pow (a, (double )b)};
60
62
}
61
63
}
@@ -119,12 +121,11 @@ class Value {
119
121
std::to_string (op)};
120
122
}
121
123
if constexpr (is_integral<i_t >) {
122
- return returnInt (result);
124
+ return returnInt (std::move ( result) );
123
125
} else {
124
126
return Value{result};
125
127
}
126
128
}
127
- return Value{};
128
129
},
129
130
value_, o.value_ );
130
131
}
@@ -148,7 +149,7 @@ class Value {
148
149
}
149
150
throw std::invalid_argument (
150
151
absl::StrCat (" Value (" , typeid (U).name (), " )" , str (),
151
- " not suitable for loop counter " ));
152
+ " not suitable for " , typeid (T). name () ));
152
153
},
153
154
value_);
154
155
}
@@ -171,11 +172,12 @@ class Value {
171
172
" insufficient long double precision" );
172
173
return (long double )a < (long double )b;
173
174
} else if constexpr (std::is_same_v<T, double >) {
175
+ static_assert (std::is_same_v<U, integer>);
174
176
return (boost::multiprecision::mpq_rational)a < b;
175
- } else if constexpr (std::is_same_v<U, double >) {
176
- return a < (boost::multiprecision::mpq_rational)b;
177
177
} else {
178
- throw std::logic_error (" programmer error" );
178
+ static_assert (std::is_same_v<U, double >);
179
+ static_assert (std::is_same_v<T, integer>);
180
+ return a < (boost::multiprecision::mpq_rational)b;
179
181
}
180
182
}
181
183
},
0 commit comments