I'm trying to write a type trait to detect if a type has overloaded operator<<() suitable to use to an output stream.
I'm missing something because I'm always getting true for a simple empty class with no operators at all.
Here the code:
template<typename S, typename T>
class is_streamable
{
template<typename SS, typename TT>
static auto test(SS&& s, TT&& t)
-> decltype(std::forward<SS>(s) << std::forward<TT>(t));
struct dummy_t {};
static dummy_t test(...);
using return_type = decltype(test(std::declval<S>(), std::declval<T>()));
public:
static const bool value = !std::is_same<return_type, dummy_t>::value;
};
class C {};
int main() {
std::cout << is_streamable<std::stringstream, C>::value << std::endl;
return 0;
}
Output:
1
Here it is in ideone: https://ideone.com/ikSBoT
What am I doing wrong?