#include "conversion.hpp" #include #include unsigned int str_to_uint(std::string str) { if (str.at(0) == '-') { throw "Less than 0"; } std::size_t waste_pos = 0; uint64_t num = 0; try { num = std::stoul(str, &waste_pos, NUMBER_BASE); } catch (const std::invalid_argument &exc) { throw "Not a number"; } catch (const std::out_of_range &exc) { throw "Out of range"; } if (waste_pos != str.length()) { throw "Not a number"; } if (num > UINT_MAX) { throw "Out of range"; } return static_cast(num); }