I have template code which needs to convert some template type to string. For this I overload to_string for my own types. But the type can also be a string already. Then compilation fails, because there is no overload of to_string for type string itself (just returning its argument).
edit: example code:
template<class T>
class TemplatedClass
{
public:
string toString() const
{
// this should work for both simple types like int, double, ...
// and for my own classes which have a to_string overload
// and also for string, which is the reason for my question
return string("TemplatedClass: ").append(to_string(t_));
}
private:
T t_;
};
to_string. Putting your overloads in thestdnamespace is undefined behaviour.to_string(x)dousing std::to_stringbefore and the compiler will either use the overload fromstdor the one you provided by ADL.std::string, this is of course not possible. In your case, I would maketo_string( std::string const& )a member function ofTemplatedClass. Or specialize the class forstd::string.