I learnt about the SFINAE principle and its various uses. Then I wrote the following program that compiles with gcc but not with msvc and clang. Live demo.
#include <iostream>
#include <type_traits>
template <typename T> class Container {
public:
template<typename U = T>
std::enable_if_t<std::is_same_v<T, int>> foo(const T&)
{
}
};
template<typename T>
void func(T&& callable)
{
Container<int> c;
(c.*callable)(4);
}
int main(){
//works with gcc but not with clang and msvc
func(&Container<int>::foo);
}
As we can see the above program works with gcc but not with clang and msvc and I don't know which compiler is right here. So is this program well-formed or ill-formed etc.