Skip to content

implementation of p2497 #314

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

implementation of p2497 #314

wants to merge 5 commits into from

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.

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