Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiling error under gcc-10 (#194) #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions programs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ if(CSV_DEVELOPER)
return 0;
}
" haveCharconv)

check_cxx_source_compiles("
#include <charconv>

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)

Expand Down
6 changes: 6 additions & 0 deletions programs/data_type_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ long double get_max(std::string file, std::string column, bool use_std) {

if (use_std) {
auto _field = field.get<std::string_view>();
#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<long double>();
Expand Down