I have a class template defined as follow
template<typename T>
class A
{
T t_;
// void f();
};
My question is how to add the f() method only if the type T is integer without compilation error.
int main()
{
A<int> a; // OK
A<string> b; // OK
}
Example :
#include <type_traits>
#include <new>
#include <iostream>
#include <string>
template <typename T>
struct Foo
{
T t;
template <typename..., typename U = T>
std::enable_if_t<std::is_same_v<T, int>> say_hello() { std::cout << "Hello"; }
};
int main()
{
Foo<int>();
Foo<double>();
}
Error C2938 'std::enable_if_t<false,void>' : Failed to specialize alias template
Thank you.