76 const char *first,
const char *last, T &value,
77 [[maybe_unused]] std::chars_format fmt = std::chars_format::general) {
80 if constexpr (std::is_same_v<T, float>)
81 value = std::stof(std::string(first, last), &end_index);
82 else if constexpr (std::is_same_v<T, double>)
83 value = std::stod(std::string(first, last), &end_index);
84 else if constexpr (std::is_same_v<T, long double>)
85 value = std::stold(std::string(first, last), &end_index);
87 static_assert(std::is_same_v<T, void>);
88 }
catch (std::invalid_argument &e) {
91 .ec = std::errc::invalid_argument,
93 }
catch (std::out_of_range &e) {
95 .ptr = first + end_index,
96 .ec = std::errc::result_out_of_range,
100 .ptr = first + end_index,
112std::from_chars_result
from_chars(
const char *first,
const char *last, T &value,
114 size_t end_index = 0;
116 if constexpr (std::is_same_v<T, signed char>)
117 value =
static_cast<signed char>(
118 std::stoi(std::string(first, last), &end_index, base));
119 else if constexpr (std::is_same_v<T, short>)
120 value =
static_cast<short>(
121 std::stoi(std::string(first, last), &end_index, base));
122 else if constexpr (std::is_same_v<T, int>)
123 value = std::stoi(std::string(first, last), &end_index, base);
124 else if constexpr (std::is_same_v<T, long>)
125 value = std::stol(std::string(first, last), &end_index, base);
126 else if constexpr (std::is_same_v<T, long long>)
127 value = std::stoll(std::string(first, last), &end_index, base);
128 else if constexpr (std::is_same_v<T, unsigned char>)
129 value =
static_cast<unsigned char>(
130 std::stoul(std::string(first, last), &end_index, base));
131 else if constexpr (std::is_same_v<T, unsigned short>)
132 value =
static_cast<unsigned short>(
133 std::stoul(std::string(first, last), &end_index, base));
134 else if constexpr (std::is_same_v<T, unsigned int>)
135 value =
static_cast<unsigned int>(
136 std::stoul(std::string(first, last), &end_index, base));
137 else if constexpr (std::is_same_v<T, unsigned long>)
138 value = std::stoul(std::string(first, last), &end_index, base);
139 else if constexpr (std::is_same_v<T, unsigned long long>)
140 value = std::stoull(std::string(first, last), &end_index, base);
142 static_assert(std::is_same_v<T, void>);
143 }
catch (std::invalid_argument &e) {
146 .ec = std::errc::invalid_argument,
148 }
catch (std::out_of_range &e) {
150 .ptr = first + end_index,
151 .ec = std::errc::result_out_of_range,
155 .ptr = first + end_index,