fork(3) download
  1. #include <type_traits>
  2.  
  3. struct CByteArray {};
  4.  
  5. struct CIODevice {
  6. template <typename T>
  7. CIODevice& operator<< (T value)
  8. {
  9. static_assert(std::is_pod<T>::value, "This method is only intended for POD types");
  10. return *this;
  11. }
  12.  
  13. template <>
  14. CIODevice& operator<< (CByteArray data)
  15. {
  16. return *this;
  17. }
  18.  
  19. template <typename T>
  20. CIODevice& operator>> (T& value)
  21. {
  22. static_assert(std::is_pod<T>::value, "This method is only intended for POD types");
  23. return *this;
  24. }
  25. };
  26.  
  27. int main()
  28. {
  29. CIODevice device;
  30. int i = 0;
  31. device << i;
  32. device >> i;
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:13:12: error: explicit specialization in non-namespace scope ‘struct CIODevice’
  template <>
            ^
prog.cpp:20:11: error: too many template-parameter-lists
  CIODevice& operator>> (T& value)
           ^
prog.cpp: In function ‘int main()’:
prog.cpp:32:9: error: no match for ‘operator>>’ (operand types are ‘CIODevice’ and ‘int’)
  device >> i;
         ^
stdout
Standard output is empty