File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,15 +198,30 @@ inline int get_max_digits10(const Real& value) {
198198 return std::numeric_limits<Real>::max_digits10;
199199}
200200
201+ namespace detail {
202+ template <typename To>
203+ typename std::enable_if<std::is_constructible<To, const char *>::value, To>::type
204+ sstream_convert_extract (std::stringstream& ss) {
205+ return To (ss.str ().c_str ());
206+ }
207+
208+ template <typename To>
209+ typename std::enable_if<!std::is_constructible<To, const char *>::value, To>::type
210+ sstream_convert_extract (std::stringstream& ss) {
211+ To to;
212+ ss >> to;
213+ return to;
214+ }
215+ } // namespace detail
216+
201217template <typename To, typename From>
202218typename std::enable_if<!std::is_same<typename std::decay<To>::type,
203219 typename std::decay<From>::type>::value,
204220 To>::type
205221sstream_convert (From&& from) {
206222 std::stringstream ss;
207223 ss << std::scientific << std::setprecision (get_max_digits10 (from)) << from;
208- To to (ss.str ().c_str ());
209- return to;
224+ return detail::sstream_convert_extract<To>(ss);
210225}
211226
212227template <typename To>
You can’t perform that action at this time.
0 commit comments