mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
add script to generate single header
This commit is contained in:
@@ -17,6 +17,9 @@ namespace ss {
|
||||
// number converters
|
||||
////////////////
|
||||
|
||||
#define SSP_DISABLE_FAST_FLOAT
|
||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||
|
||||
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) {
|
||||
@@ -29,6 +32,31 @@ std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> to_num(
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
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) {
|
||||
T ret;
|
||||
try {
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
ret = std::stof(std::string{begin, end});
|
||||
}
|
||||
if constexpr (std::is_same_v<T, double>) {
|
||||
ret = std::stod(std::string{begin, end});
|
||||
}
|
||||
if constexpr (std::is_same_v<T, long double>) {
|
||||
ret = std::stold(std::string{begin, end});
|
||||
}
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline std::optional<short> from_char(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
|
||||
Reference in New Issue
Block a user