As Nicol Bolas pointed out, to_string
is never a template, but just a group of overloaded functions. Making such functions templates are not good, as doing them generically is probably not efficient, and can only behave like stringstreams. So from_string
, similarly, should not be function templates, but rather simple functions. Since their argument is the same type (std::string
), their names should not be the same. So stoi
, stof
, and the like are really what you wanted.
to_string
and sto*
also behave similarly regarding the locale: they all respect the current C locale. The C++ IOStreams, on the contrary, are not affected by the C locale. They can be overridden only if they are created after the C++ global locale is set by std::locale::global
, or are manually imbue
’d with a different locale.
std::stoi
and family. – Xistd::sto
… series not a template?" may be of interest. – Alkylto_string
series are not template functions. And they are limited to numeric types. Note that you cannot add overloads to thestd
namespace. – Goyettefrom_string
. Do you know if any such proposal exists? Have you done the research to find any such proposal? – Goyetteto_string
is not the inverse of his suggestedfrom_string
. – Goyette