If I'm not mistaken you can simply overload to_string
for a generic type:
template to_string(const T& _x) {
return _x.toString();
}
and this allows use of ADL (argument dependent lookup) by your program to correctly choose the relevant to_string
method based upon the type passed.