template<typename T, size_t length> void f(T (&)[length]){
cout<<"array"<<endl;
}
template<typename T> void f(T&){
cout<<"generic"<<endl;
}
template<typename T, typename enable_if<is_array<T>::value, int>::type =0> void f(T&){
cout<<"generic (is array)"<<endl;
}
is there any case (that is, any T when calling f<T>()) in which the last version of the function template will be preferred on top of the others?
No. If
Tis an array type, the first version wins over the second and third function (otherwise the second and third function would be ambiguous). IfTis not an array type, the third function is not available, thanks toenable_if, and since the first one doesn’t match, the second one will be used.