Skip to content

Commit

Permalink
[cross] Add fix in case from_chars(double) is not there
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier authored Sep 14, 2023
1 parent 86e75d7 commit 1106e1e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/avnd/binding/max/from_atoms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <avnd/common/concepts_polyfill.hpp>
#include <avnd/common/aggregates.hpp>
#if !defined(__cpp_lib_to_chars)
#include <boost/lexical_cast.hpp>
#else
#include <charconv>
#endif
#include <string>
#include <ext.h>

Expand Down Expand Up @@ -35,12 +39,20 @@ struct from_atom
if(sym && sym->s_name)
{
double vv{};
#if defined(__cpp_lib_to_chars)
auto [_, ec] = std::from_chars(sym->s_name, sym->s_name + strlen(sym->s_name), vv);
if(ec == std::errc{})
{
v = vv;
return true;
}
#else
if(boost::conversion::try_lexical_convert(str, vv))
{
v = vv;
return true;
}
#endif
}
return false;
}
Expand Down

0 comments on commit 1106e1e

Please sign in to comment.