fork(7) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <type_traits>
  4.  
  5. template<typename S, typename T>
  6. class is_streamable
  7. {
  8. template<typename SS, typename TT>
  9. static auto test(SS&& s, TT&& t)
  10. -> decltype(std::forward<SS>(s) << std::forward<TT>(t));
  11.  
  12. struct dummy_t {};
  13. static dummy_t test(...);
  14.  
  15. using return_type = decltype(test(std::declval<S>(), std::declval<T>()));
  16.  
  17. public:
  18. static const bool value = !std::is_same<return_type, dummy_t>::value;
  19. };
  20.  
  21. class C {};
  22.  
  23. int main() {
  24. std::cout <<is_streamable<std::stringstream, C>::value << std::endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
1