Skip to content

Commit e6867f5

Browse files
committed
Fix wording
1 parent 4bb6fd1 commit e6867f5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,44 @@ Example:
5858
#include "fast_float/fast_float.h"
5959
#include <iostream>
6060
#include <string>
61+
#include <system_error>
6162
6263
int main() {
63-
std::string input = "3.1416 xyz ";
64+
const std::string input = "3.1416 xyz ";
6465
double result;
6566
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
66-
if (answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; }
67-
std::cout << "parsed the number " << result << std::endl;
67+
if (answer.ec != std::errc()) {
68+
std::cerr << "parsing failure\n";
69+
return EXIT_FAILURE;
70+
}
71+
std::cout << "parsed the number " << result << '\n';
6872
return EXIT_SUCCESS;
6973
}
7074
```
7175

72-
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:
76+
Prior to C++26, checking for a successful `std::from_chars` conversion requires comparing the `from_chars_result::ec` member to `std::errc()`. As an extension `fast_float::from_chars` supports the improved C++26 API that allows checking the result by converting it to `bool`, like so:
7377

74-
```cpp
78+
```C++
7579
#include "fast_float/fast_float.h"
7680
#include <iostream>
7781
#include <string>
7882

7983
int main() {
80-
std::string input = "3.1416 xyz ";
84+
const std::string input = "3.1416 xyz ";
8185
double result;
82-
if(auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result)) {
83-
std::cout << "parsed the number " << result << std::endl;
86+
if (auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result)) {
87+
std::cout << "parsed the number " << result << '\n';
8488
return EXIT_SUCCESS;
8589
}
86-
std::cerr << "failed to parse " << result << std::endl;
90+
std::cerr << "parsing failure\n";
8791
return EXIT_FAILURE;
8892
}
8993
```
9094

9195
You can parse delimited numbers:
9296

9397
```C++
94-
std::string input = "234532.3426362,7869234.9823,324562.645";
98+
const std::string input = "234532.3426362,7869234.9823,324562.645";
9599
double result;
96100
auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result);
97101
if (answer.ec != std::errc()) {

0 commit comments

Comments
 (0)