fast_float
fast_float copied to clipboard
implementation of p2497
Though the C++17 standard has you do a comparison with std::errc() to check whether the conversion worked, you can avoid it by casting the result to a bool like so:
#include "fast_float/fast_float.h"
#include <iostream>
#include <string>
int main() {
std::string input = "3.1416 xyz ";
double result;
if(auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result)) {
std::cout << "parsed the number " << result << std::endl;
return EXIT_SUCCESS;
}
std::cerr << "failed to parse " << result << std::endl;
return EXIT_FAILURE;
}
This was proposed by @jwakely in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2497r0.html
I am also refreshing the CMake.