What does the C++ standard have to say about overloading/implementing a templatized version of std::to_string like so:
#include <string>
#include <sstream>
#include <ostream>
namespace std {
template<typename T>
string to_string(const T& in)
{
ostringstream oss;
oss << in;
return oss.str();
}
}
Is this expressedly disallowed? Or cause nasal-daemons to fly out of the nose?
g++ accepts the above code with --std=c++11 -Wextra -pedantic-errors, reports no errors, and the executable generates the output that I expect (which, of course, does not mean anything in context to my question)
std::std::to_stringwhen possible and falls back to your implementation otherwise. There is no issue with thatto_stringfunction in that namespace that takes the specific classes as arguments. Then the compiler can use argument-dependent lookup to find the function if you just call it asto_string(object_of_namespace_class).std::to_string.