Select class constructor using enable_if

I think this can’t work with a single defaulted template parameter, because its value needs to be resolved when the class template is instantiated.

We need to defer the substitution to the point of constructor template instantiation. One way is to default the template parameter to T and add an extra dummy parameter to the constructor:

template<typename U = T>
A(int n, typename std::enable_if<U::value>::type* = 0) : val(n) { }

Leave a Comment