From 7a3edb0437f393bb7bef484ecec7b198093474be Mon Sep 17 00:00:00 2001 From: tianxing Date: Tue, 16 Jul 2024 09:37:37 +0800 Subject: [PATCH] Fix compiling error under gcc-10 (#194) --- programs/CMakeLists.txt | 14 ++++++++++++++ programs/data_type_bench.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 642cc2cf..1aa0aaec 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -27,12 +27,26 @@ if(CSV_DEVELOPER) return 0; } " haveCharconv) + + check_cxx_source_compiles(" + #include + + int main(int argc, char** argv) { + const char* str = \"123.456\"; + long double d; + std::from_chars(str, str + 7, d); + return 0; + } + " FROM_CHARS_SUPPORT_DOUBLE) if(haveCharconv) add_executable(csv_generator ${CMAKE_CURRENT_LIST_DIR}/csv_generator.cpp) target_link_libraries(csv_generator csv) # Benchmarks for data_type() function + if(FROM_CHARS_SUPPORT_DOUBLE) + add_definitions(-DFROM_CHARS_SUPPORT_DOUBLE) + endif() add_executable(data_type_bench ${CMAKE_CURRENT_LIST_DIR}/data_type_bench.cpp) target_link_libraries(data_type_bench csv) diff --git a/programs/data_type_bench.cpp b/programs/data_type_bench.cpp index aa76be5c..ff6bfecc 100644 --- a/programs/data_type_bench.cpp +++ b/programs/data_type_bench.cpp @@ -18,11 +18,17 @@ long double get_max(std::string file, std::string column, bool use_std) { if (use_std) { auto _field = field.get(); +#ifdef FROM_CHARS_SUPPORT_DOUBLE auto data = _field.data(); std::from_chars( data, data + _field.size(), out ); +#else + std::string str(_field); + std::stringstream ss(str); + ss >> out; +#endif } else { out = field.get();