Skip to content

Commit 64883ca

Browse files
committed
apple support for from_chars
1 parent ec27130 commit 64883ca

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/featureFilegen.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <charconv>
99
#include <algorithm>
1010
#include "FeatureStore.hpp"
11+
#include <type_traits>
1112
#include <omp.h>
1213

1314
// PLATFORM DEPENDENT INCLUDES
@@ -83,7 +84,20 @@ void parse_and_write_features(const std::string& csv_path, char* map_addr, uint6
8384

8485
// Parse the correct type T
8586
T feature_value;
86-
std::from_chars(feature_str.data(), feature_str.data() + feature_str.size(), feature_value);
87+
#if defined(__APPLE__)
88+
// Apple's libc++ doesn't support float from_chars yet, so we safely fallback
89+
if constexpr (std::is_same_v<T, float>) {
90+
feature_value = std::stof(std::string(feature_str));
91+
} else if constexpr (std::is_same_v<T, double>) {
92+
feature_value = std::stod(std::string(feature_str));
93+
} else {
94+
// Apple does support it for integers!
95+
std::from_chars(feature_str.data(), feature_str.data() + feature_str.size(), feature_value);
96+
}
97+
#else
98+
// Windows and Linux get the ultra-fast C++17 standard parsing
99+
std::from_chars(feature_str.data(), feature_str.data() + feature_str.size(), feature_value);
100+
#endif
87101

88102
feature_data_ptr[node_id * feature_dim + f] = feature_value;
89103

0 commit comments

Comments
 (0)