| 167 | // Convenience functions over an arbitrary number of arguments |
| 168 | template <typename Int> |
| 169 | std::optional<Int> AddWithOverflow(std::initializer_list<Int> vs) { |
| 170 | if (vs.size() == 0) { |
| 171 | return {}; |
| 172 | } |
| 173 | auto it = vs.begin(); |
| 174 | Int v = *it++; |
| 175 | while (it != vs.end()) { |
| 176 | if (ARROW_PREDICT_FALSE(AddWithOverflowGeneric(v, *it++, &v))) { |
| 177 | return {}; |
| 178 | } |
| 179 | } |
| 180 | return v; |
| 181 | } |
| 182 | |
| 183 | template <typename Int> |
| 184 | std::optional<Int> MultiplyWithOverflow(std::initializer_list<Int> vs) { |