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
12 changes: 12 additions & 0 deletions hardware_interface/src/lexical_casts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace hardware_interface
{
double stod(const std::string & s)
#if __cplusplus > 201703L
{
// convert from string using no locale
std::istringstream stream(s);
Expand All @@ -29,7 +30,18 @@ double stod(const std::string & s)
}
return result;
}
#else
{
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;
#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