Skip to content

validation.h: stold => std::from_chars #224

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions headers/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ class Validator {

public:
// No copying, no moving.
Validator(const Validator&) = delete;
Validator(Validator&&) = delete;
Validator(const Validator&) = delete;
Validator(Validator&&) = delete;
void operator=(const Validator&) = delete;
void operator=(Validator&&) = delete;
void operator=(Validator&&) = delete;

// At the end of the scope, check whether the EOF has been reached.
// If so, return AC. Otherwise, return WA.
Expand Down Expand Up @@ -1266,11 +1266,11 @@ class Validator {
long long v;
auto begin = s.c_str(), end = begin + s.size();
auto [ptr, ec] = std::from_chars(begin, end, v);
if(ec == std::errc::result_out_of_range){
if(ec == std::errc::result_out_of_range) {
WA(name, ": Number " + s + " does not fit in a long long!");
} else if(ptr != end) {
WA(name, ": Parsing " + s + " as long long failed! Did not process all characters");
} else if (ec != std::errc{}) {
} else if(ec != std::errc{}) {
WA(name, ": Parsing " + s + " as long long failed!");
}
// Check for leading zero.
Expand All @@ -1291,16 +1291,14 @@ class Validator {
assert(!gen);
std::string s = get_string("long double");
long double v;
try {
size_t chars_processed;
v = stold(s, &chars_processed);
if(chars_processed != s.size())
WA(name, ": Parsing ", s,
" as long double failed! Did not process all characters.");
} catch(const std::out_of_range& e) {
auto begin = s.c_str(), end = begin + s.size();
auto [ptr, ec] = std::from_chars(begin, end, v);
if(ec == std::errc::result_out_of_range) {
WA(name, ": Number " + s + " does not fit in a long double!");
} catch(const std::invalid_argument& e) {
WA("Parsing " + s + " as long double failed!");
} else if(ptr != end) {
WA(name, ": Parsing " + s + " as long double failed! Did not process all characters");
} else if(ec != std::errc{}) {
WA(name, ": Parsing " + s + " as long double failed!");
}
return v;
}
Expand Down