Hello I want to write two implementations of the to_string member function as follows:
template <typename T0> class foo
{
public: std::string to_string();
public: T0 m_Value;
};
template <typename T0> std::string foo<T0>::to_string()
{
std::stringstream ss;
ss << m_Value;
return ss.str();
}
template <typename T0> std::string foo<T0>::to_string()
{
return typeid(T0).name();
}
I have seen this, however I don't know how to use the code, I'm not used to enable_if and boost mpl at all. How should I define the two to_string functions to use the second as a fallback?
Thanks.
has_insertion_operatorwas copied from the linked answer by Paul J. Lucas in (Using SFINAE to check for global operator<<?).You could also use the inline friend solution of Mike Seymour shown in (How to convert anything to string implicitly?). I prefer the SFINAE though.