I have some code that boils down to this:
#include <type_traits>
struct CByteArray {};
struct CIODevice {
template <typename T>
CIODevice& operator<< (T value)
{
static_assert(std::is_pod<T>::value, "This method is only intended for POD types");
return *this;
}
template <>
CIODevice& operator<< (CByteArray data)
{
return *this;
}
template <typename T>
CIODevice& operator>> (T& value)
{
static_assert(std::is_pod<T>::value, "This method is only intended for POD types");
return *this;
}
};
int main()
{
CIODevice device;
int i = 0;
device << i;
device >> i;
return 0;
}
It compiles in MSVC, but in GCC I get this:
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;
^
I don't get it, what's the mistake here?