diff --git a/include/libint2/numeric.h b/include/libint2/numeric.h index 2db7ade46..549f049f2 100644 --- a/include/libint2/numeric.h +++ b/include/libint2/numeric.h @@ -198,6 +198,22 @@ inline int get_max_digits10(const Real& value) { return std::numeric_limits::max_digits10; } +namespace detail { +template +typename std::enable_if::value, To>::type +sstream_convert_extract(std::stringstream& ss) { + return To(ss.str().c_str()); +} + +template +typename std::enable_if::value, To>::type +sstream_convert_extract(std::stringstream& ss) { + To to; + ss >> to; + return to; +} +} // namespace detail + template typename std::enable_if::type, typename std::decay::type>::value, @@ -205,8 +221,7 @@ typename std::enable_if::type, sstream_convert(From&& from) { std::stringstream ss; ss << std::scientific << std::setprecision(get_max_digits10(from)) << from; - To to(ss.str().c_str()); - return to; + return detail::sstream_convert_extract(ss); } template