| 202 | |
| 203 | template <typename Int> |
| 204 | std::optional<Int> MultiplyWithOverflow(std::initializer_list<Int> vs) { |
| 205 | if (vs.size() == 0) { |
| 206 | return {}; |
| 207 | } |
| 208 | auto it = vs.begin(); |
| 209 | Int v = *it++; |
| 210 | while (it != vs.end()) { |
| 211 | if (ARROW_PREDICT_FALSE(MultiplyWithOverflowGeneric(v, *it++, &v))) { |
| 212 | return {}; |
| 213 | } |
| 214 | } |
| 215 | return v; |
| 216 | } |
| 217 | |
| 218 | // Define function NegateWithOverflow with the signature `bool(T u, T* out)` |
| 219 | // where T is a signed integer type. On overflow, these functions return true. |