util/NumberParser: add std::from_chars() wrapper taking std::string_view

This commit is contained in:
Max Kellermann 2025-03-07 09:11:42 +01:00 committed by Max Kellermann
parent 103487e8ad
commit e9c1ea684b

@ -8,6 +8,16 @@
#include <optional>
#include <string_view>
/**
* A std::from_chars() wrapper taking a std::string_view. How
* annoying that the C++ standard library doesn't allow this!
*/
inline std::from_chars_result
FromChars(std::string_view s, std::integral auto &value, int base=10) noexcept
{
return std::from_chars(s.data(), s.data() + s.size(), value, base);
}
template<std::integral T>
[[gnu::pure]]
std::optional<T>