| 6106 | } |
| 6107 | |
| 6108 | static std::size_t string_to_integer_or_throw( // |
| 6109 | std::string const &value, [[maybe_unused]] std::size_t iteration_index) noexcept(false) { |
| 6110 | // The `std::stoull` function may throw: |
| 6111 | // - `std::invalid_argument` if no conversion could be performed. |
| 6112 | // - `std::out_of_range` if the converted value would fall out of the range of the |
| 6113 | // result type or if the underlying function sets `errno` to `ERANGE`. |
| 6114 | // The cleaner modern way to implement this is using `std::from_chars` in C++17. |
| 6115 | std::size_t integral_value = 0; |
| 6116 | std::from_chars_result result = std::from_chars(value.data(), value.data() + value.size(), integral_value); |
| 6117 | if (result.ec != std::errc()) throw std::out_of_range("Conversion failed"); |
| 6118 | return integral_value; |
| 6119 | } |
| 6120 | |
| 6121 | static std::string integer_to_next_string_or_throw(std::size_t value, std::size_t iteration_index) noexcept(false) { |
| 6122 | if (iteration_index % fail_period_next_string_k == 0) throw std::runtime_error("Increment failed"); |