[base] Added to_uint base for string_view.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2025-07-05 11:18:08 -03:00
committed by Konstantin Pastbin
parent 1d29e7816a
commit 72ff90defd
2 changed files with 8 additions and 4 deletions

View File

@@ -538,19 +538,19 @@ bool ToInteger(char const * start, T & result, int base = 10)
namespace impl
{
template <typename T>
bool from_sv(std::string_view sv, T & t)
bool from_sv(std::string_view sv, T & t, int base = 10)
{
auto const end = sv.data() + sv.size();
auto const res = std::from_chars(sv.data(), end, t);
auto const res = std::from_chars(sv.data(), end, t, base);
return (res.ec != std::errc::invalid_argument && res.ec != std::errc::result_out_of_range && res.ptr == end);
}
} // namespace impl
template <class T>
inline bool to_uint(std::string_view sv, T & i)
inline bool to_uint(std::string_view sv, T & i, int base = 10)
{
static_assert(std::is_unsigned<T>::value, "");
return impl::from_sv(sv, i);
return impl::from_sv(sv, i, base);
}
inline bool to_double(std::string_view sv, double & d)