diff --git a/include/ss/extract.hpp b/include/ss/extract.hpp index 2e9e6f0..52aa0f9 100644 --- a/include/ss/extract.hpp +++ b/include/ss/extract.hpp @@ -17,6 +17,9 @@ namespace ss { // number converters //////////////// +#define SSP_DISABLE_FAST_FLOAT +#ifndef SSP_DISABLE_FAST_FLOAT + template std::enable_if_t, std::optional> to_num( const char* const begin, const char* const end) { @@ -29,6 +32,31 @@ std::enable_if_t, std::optional> to_num( return ret; } +#else + +template +std::enable_if_t, std::optional> to_num( + const char* const begin, const char* const end) { + T ret; + try { + if constexpr (std::is_same_v) { + ret = std::stof(std::string{begin, end}); + } + if constexpr (std::is_same_v) { + ret = std::stod(std::string{begin, end}); + } + if constexpr (std::is_same_v) { + ret = std::stold(std::string{begin, end}); + } + } catch (...) { + return std::nullopt; + } + + return ret; +} + +#endif + inline std::optional from_char(char c) { if (c >= '0' && c <= '9') { return c - '0'; diff --git a/script/single_header_generator.py b/script/single_header_generator.py new file mode 100755 index 0000000..3916666 --- /dev/null +++ b/script/single_header_generator.py @@ -0,0 +1,34 @@ +#!/bin/python3 + +headers_dir = 'include/ss/' +headers = ['type_traits.hpp', + 'function_traits.hpp', + 'restrictions.hpp', + 'common.hpp', + 'setup.hpp', + 'splitter.hpp', + 'extract.hpp', + 'converter.hpp', + 'parser.hpp'] + +combined_file = [] +includes = [] + +for header in headers: + with open(headers_dir + header) as f: + for line in f.read().splitlines(): + if '#include "' in line or '#include