Add std::stou, cant believe its not in the STL

This commit is contained in:
Riyyi
2021-02-01 03:55:19 +01:00
parent 54171260b6
commit 9734e7fbe0
+28
View File
@@ -0,0 +1,28 @@
#ifndef UTIL_STRING_H
#define UTIL_STRING_H
#include <limits> // std::numeric_limits
#include <string> // std::string, std::stoul
#include "inferno/assert.h"
namespace std {
// Can't believe this is not in the standard library
inline uint32_t stou(const char* string)
{
unsigned long size = std::stoul(string);
ASSERT(size <= std::numeric_limits<uint32_t>::max(), "String util not in uint32_t range '{}'", string);
return static_cast<uint32_t>(size);
}
inline uint32_t stou(const std::string& string)
{
return stou(string.c_str());
}
} // namespace std
#endif // UTIL_STRING_H