10#ifndef CPROVER_UTIL_STRING2INT_H
11#define CPROVER_UTIL_STRING2INT_H
49std::optional<unsigned>
55std::optional<std::size_t>
68 PRECONDITION(base == 2 || base == 8 || base == 10 || base == 16);
71 std::is_integral<T>::value,
"string2optional requires an integral type");
77 if(std::is_unsigned<T>::value && str.front() ==
'-')
80 const char *first = str.data();
81 const char *last = str.data() + str.size();
84 auto [ptr,
ec] = std::from_chars(first, last, value, base);
86 if(
ec != std::errc{} || ptr != last)
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
#define PRECONDITION(CONDITION)
std::optional< std::size_t > string2optional_size_t(std::string_view, int base=10)
Convert string to size_t similar to the stoul or stoull functions, return nullopt when the conversion...
long long int unsafe_string2signedlonglong(const std::string &, int base=10)
std::optional< unsigned > string2optional_unsigned(std::string_view, int base=10)
Convert string to unsigned similar to the stoul or stoull functions, return nullopt when the conversi...
std::size_t unsafe_string2size_t(const std::string &, int base=10)
std::optional< int > string2optional_int(std::string_view, int base=10)
Convert string to integer as per stoi, but return nullopt when stoi would throw.
std::optional< T > string2optional(std::string_view str, int base=10)
Convert a string to an integer, given the base of the representation, works with signed and unsigned ...
unsigned safe_string2unsigned(std::string_view, int base=10)
unsigned unsafe_string2unsigned(const std::string &, int base=10)
std::size_t safe_string2size_t(std::string_view, int base=10)
int unsafe_string2int(const std::string &, int base=10)
long long unsigned int unsafe_string2unsignedlonglong(const std::string &, int base=10)