7#include "../macros.hpp"
9#include "exception.hpp"
16hi_export_module(hikogui.utility.charconv);
18hi_export
namespace hi {
inline namespace v1 {
26template<std::
integral T>
31 auto const first = buffer.
data();
32 auto const last = first + buffer.
size();
34 auto const[new_last, ec] = std::to_chars(first, last, value);
48template<std::
floating_po
int T>
49[[nodiscard]]
std::string to_string(T
const &value)
noexcept
53 auto const first = buffer.
data();
54 auto const last = first + buffer.
size();
56 auto const[new_last, ec] = std::to_chars(first, last, value, std::chars_format::general);
72template<std::
integral T>
73[[nodiscard]] T
from_string(std::string_view str,
int base = 10)
77 auto const first = str.data();
78 auto const last = first + ssize(str);
80 auto const[new_last, ec] = std::from_chars(first, last, value, base);
81 if (ec !=
std::errc{} or new_last != last) {
82 throw parse_error(
"Can not convert string to integer");
95template<std::
floating_po
int T>
100 auto const first = str.data();
101 auto const last = first + ssize(str);
103 auto const[new_last, ec] = std::from_chars(first, last, value);
104 if (ec !=
std::errc{} or new_last != last) {
105 throw parse_error(
"Can not convert string to floating point");
Utilities for throwing exceptions and terminating the application.
The HikoGUI namespace.
Definition array_generic.hpp:20
T from_string(std::string_view str, int base=10)
Convert a string to an integer.
Definition charconv.hpp:73
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Exception thrown during parsing on an error.
Definition exception_intf.hpp:48
T back_inserter(T... args)