Skip to content
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

adding backward compatibility for string-to-double conversion #1284

Merged
merged 10 commits into from
Jan 12, 2024
14 changes: 14 additions & 0 deletions hardware_interface/src/lexical_casts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace hardware_interface
{

#if __cplusplus > 201402L
bailaC marked this conversation as resolved.
Show resolved Hide resolved
bailaC marked this conversation as resolved.
Show resolved Hide resolved
double stod(const std::string & s)
bailaC marked this conversation as resolved.
Show resolved Hide resolved
{
// convert from string using no locale
Expand All @@ -29,7 +31,19 @@ double stod(const std::string & s)
}
return result;
}
#else
double stod(const std::string & text)
bailaC marked this conversation as resolved.
Show resolved Hide resolved
{
double result_value;
const auto parse_result = std::from_chars(text.data(), text.data() + text.size(), result_value);
if (parse_result.ec == std::errc())
{
return result_value;
}

return 0.0;
}
bailaC marked this conversation as resolved.
Show resolved Hide resolved
#endif
bailaC marked this conversation as resolved.
Show resolved Hide resolved
bool parse_bool(const std::string & bool_string)
{
return bool_string == "true" || bool_string == "True";
Expand Down
Loading