| 477 | |
| 478 | template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>> |
| 479 | bool ToInteger(char const * start, T & result, int base = 10) |
| 480 | { |
| 481 | char * stop; |
| 482 | errno = 0; // Library functions do not reset it. |
| 483 | |
| 484 | auto const v = IntConverter<T>(start, &stop, base); |
| 485 | |
| 486 | if (errno == EINVAL || errno == ERANGE || *stop != 0 || start == stop || !base::IsCastValid<T>(v)) |
| 487 | { |
| 488 | errno = 0; |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | result = static_cast<T>(v); |
| 493 | return true; |
| 494 | } |
| 495 | } // namespace internal |
| 496 | |
| 497 | [[nodiscard]] inline bool to_int(char const * s, int & i, int base = 10) |