I want to have several overloaded, global to_string() functions that take some type T and convert it to its string representation. For the general
I should have simply been more faithful to this answer. A working implementation is:
namespace has_insertion_operator_impl {
typedef char no;
typedef char yes[2];
struct any_t {
template any_t( T const& );
};
no operator<<( std::ostream const&, any_t const& );
yes& test( std::ostream& );
no test( no );
template
struct has_insertion_operator {
static std::ostream &s;
static T const &t;
static bool const value = sizeof( test(s << t) ) == sizeof( yes );
};
}
template
struct has_insertion_operator :
has_insertion_operator_impl::has_insertion_operator {
};
I believe that it does not actually rely on SFINAE.