util/NumberParser: add std::from_chars() wrapper taking std::string_view
This commit is contained in:

committed by
Max Kellermann

parent
103487e8ad
commit
e9c1ea684b
@ -8,6 +8,16 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string_view>
|
#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>
|
template<std::integral T>
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
std::optional<T>
|
std::optional<T>
|
||||||
|
Reference in New Issue
Block a user