I would like to write a generic function in C++
template<class T>
string GetDebugString(const T& t);
which can universally gets debug string for all types. My problem is how to use traits to distinguish between different types:
1) Primitive types and strings: get its string representation directly.
2) Struct and class type: call its "string DebugString()" method. I would implement this method for all classes. The method would possiblely call GetDebugString recursively.
3) Pointers and smart pointers: Dereference them and follow 1) or 2)
4) Collections like vector, set or map: Iterate over all its element, get debug string for each element following 1), 2) and 3) and assemble them in some formats.
How can we do this with std::enable_if ?