Is specialization of std::to_string for custom types allowed by the C++ standard?
问题 In C++11 and later, is it allowed to specialize std::to_string in the std namespace for custom types? namespace std { string to_string(::MyClass const & c) { return c.toString(); } } Sample use-case: int main() { MyClass c; std::cout << std::to_string(c) << std::endl; } 回答1: In C++11 and later, is it allowed to specialize std::to_string in the std namespace for custom types? No. First of all, it is not a template function so you can't specialize it at all. If you're asking about adding your