10 #ifndef __NODAMUSHI_TO_INT_HPP__ 11 #define __NODAMUSHI_TO_INT_HPP__ 15 # if __cplusplus >= 201703 16 # include <string_view> 20 # include <type_traits> 25 # if __cplusplus >= 201703 26 template<
typename INT>
27 INT
to_int(std::string_view v,
int base=10)
30 std::from_chars(v.data(), v.data()+v.length(),x,base);
33 template<
typename INT>
34 INT
to_int(std::string_view v,
size_t begin,
size_t end,
int base=10)
37 std::from_chars(v.data()+begin, v.data()+end,x,base);
40 template<
typename INT>
41 INT
to_int(
const char* text,
size_t begin,
size_t end,
int base=10)
44 std::from_chars(text+begin, text+end,x,base);
47 template<
typename INT>
48 INT
to_int(
const char* text,
int base=10)
53 std::from_chars(text,end,x,base);
65 static unsigned long long conv(
const std::string& v,
int base=10)
67 return ::std::stoull(v,
nullptr,base);
72 static long long conv(
const std::string& v,
int base=10)
74 return ::std::stoll(v,
nullptr,base);
79 template<
typename INT>
80 INT
to_int(
const std::string& v,
int base=10)
82 constexpr
bool unsig = std::is_unsigned<INT>::value;
86 template<
typename INT>
87 INT
to_int(
const std::string& v,
size_t begin,
size_t end,
int base=10)
89 std::string s = v.substr(begin,end-begin);
90 return to_int<INT>(s,base);
92 template<
typename INT>
93 INT
to_int(
const char* text,
size_t begin,
size_t end,
int base=10)
95 std::string s(text+begin,text+end);
96 return to_int<INT>(s,base);
98 template<
typename INT>
99 INT
to_int(
const char* text,
int base=10)
101 const std::string s = text;
102 return to_int<INT>(s,base);
110 #endif // __TO_INT_HPP__ static unsigned long long conv(const std::string &v, int base=10)
INT to_int(const std::string &v, int base=10)
static long long conv(const std::string &v, int base=10)