Skip to content

Conversation

lemire
Copy link
Member

@lemire lemire commented May 19, 2025

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.

@lemire lemire merged commit 4bb6fd1 into main Sep 5, 2025
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant