Consider following code:
#include
#include
template
struct A {
int val = 0;
template
Usually this is done using an anonymous defaulted argument :
A(int n, typename std::enable_if::type* = 0) : val(n) {};
You can not use template parameters from the class to SFINAE out methods. SO one way is to add a dummy type replacing int :
see: http://ideone.com/2Gnyzj
#include
#include
template
struct A {
int val = 0;
template::type
>
A(Integer n) : val(n) {};
A(...) {}
/* ... */
};
struct YES { constexpr static bool value = true; };
struct NO { constexpr static bool value = false; };
int main() {
A y(10);
A n;
std::cout << "YES: " << y.val << std::endl
<< "NO: " << n.val << std::endl;
}
This works because you use a member template parameter to SFINAE out the constructor but the test is always true so it doesn't pollute your checks