The following code, which I derived reading this, compiles and behaves fine in gcc (link), but in Visual Studio gives an error.
Error C2910 '
my_property<A<U>>
': cannot be explicitly specialized
It works fine only if I remove the template <>
line.
I got the workaround here. The workaround version is ok also in g++.
#include <iostream>
#include <type_traits>
template <typename T>
struct A {
T x;
};
template <typename T>
struct my_property {
static const bool value = false;
};
template <> //Remove this and it will work in Visual Studio
template <typename U>
struct my_property<A<U>> {
static const bool value = true;
};
int main()
{
std::cout << std::boolalpha;
std::cout << my_property<int>::value << '\n'; //false
std::cout << my_property<A<int>>::value << '\n'; //true
std::cout << my_property<A<float>>::value << '\n'; //true
}
Which compiler is right?