1 #ifndef UTILS_NUMBERS_H
2 #define UTILS_NUMBERS_H
8 #include <absl/strings/numbers.h>
9 #include <absl/strings/string_view.h>
13 namespace utils_numbers_impl {
15 template<
class IntType,
class =
void>
17 static inline bool call(absl::string_view str, IntType *out) {
18 return absl::SimpleAtoi(str, out);
22 template<
class IntType>
23 struct SimpleAtoiWrapperImpl<IntType,
24 typename
std::enable_if<sizeof(IntType) <= 2>::type> {
27 typedef typename std::conditional<
28 (IntType)(1) - (IntType)(2) < 0,
30 std::uint32_t>::type int32;
32 static inline bool call(absl::string_view str, IntType *out) {
34 if (!absl::SimpleAtoi(str, &int32_out)) {
38 if (int32_out < std::numeric_limits<IntType>::min())
40 if (int32_out > std::numeric_limits<IntType>::max())
42 *out = (IntType) int32_out;
52 template<
class IntType>
bool SimpleAtoiWrapper(absl::string_view str, IntType *out)
A wrapper version of absl::SimpleAtoi that supports 1/2/4/8-byte integers.
Definition: numbers.h:53
static bool call(absl::string_view str, IntType *out)
Definition: numbers.h:17