mirror of
https://github.com/red0124/ssp.git
synced 2025-12-15 14:19:56 +01:00
Remove some comments, update README, update ssp.hpp
This commit is contained in:
21
ssp.hpp
21
ssp.hpp
@@ -1465,7 +1465,6 @@ public:
|
||||
#else
|
||||
#endif
|
||||
|
||||
// TODO try from_chars for integer conversions
|
||||
namespace ss {
|
||||
|
||||
////////////////
|
||||
@@ -1491,17 +1490,24 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
const char* const begin, const char* const end) {
|
||||
static_assert(!std::is_same_v<T, long double>,
|
||||
"Conversion to long double is disabled");
|
||||
|
||||
constexpr static auto buff_max = 64;
|
||||
char buff[buff_max];
|
||||
char short_buff[buff_max];
|
||||
size_t string_range = std::distance(begin, end);
|
||||
std::string long_buff;
|
||||
|
||||
char* buff;
|
||||
if (string_range > buff_max) {
|
||||
return std::nullopt;
|
||||
long_buff = std::string{begin, end};
|
||||
buff = long_buff.data();
|
||||
} else {
|
||||
buff = short_buff;
|
||||
buff[string_range] = '\0';
|
||||
std::copy_n(begin, string_range, buff);
|
||||
}
|
||||
|
||||
std::copy_n(begin, string_range, buff);
|
||||
buff[string_range] = '\0';
|
||||
|
||||
T ret;
|
||||
char* parse_end = nullptr;
|
||||
|
||||
@@ -1509,8 +1515,6 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
ret = std::strtof(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
ret = std::strtod(buff, &parse_end);
|
||||
} else if constexpr (std::is_same_v<T, long double>) {
|
||||
ret = std::strtold(buff, &parse_end);
|
||||
}
|
||||
|
||||
if (parse_end != buff + string_range) {
|
||||
@@ -2132,7 +2136,6 @@ private:
|
||||
|
||||
} /* ss */
|
||||
|
||||
// TODO add single header tests
|
||||
|
||||
namespace ss {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user