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
The initializer of value
on line 48 is not in a context where SFINAE works. Try moving the expression to the function declaration.
#include
struct sfinae_base {
typedef char yes[1];
typedef char no[2];
};
template
struct has_insertion_operator : sfinae_base {
// this may quietly fail:
template static yes& test(
size_t (*n)[ sizeof( std::cout << * static_cast(0) ) ] );
// "..." provides fallback in case above fails
template static no& test(...);
static bool const value = sizeof( test( NULL ) ) == sizeof( yes );
};
However, I have to question the amount of sophistication that is going into this. I see non-orthogonal mechanisms that will grind against each other (to_string
vs. operator<<
) and I hear poor assumptions getting tossed around (for example that operator<<
is global vs a member, although the code as implemented looks OK in that regard).