- SFINAE(Subtitution Faiure Is Not An Error)
#include <iostream>
using namespace std;
template<typename T>
void foo(T t) { cout << "T" << endl; }
void foo(itn t) { cout << "int" << endl; }
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // int - exactly matching
}
#include <iostream>
using namespace std;
template<typename T>
void foo(T t) { cout << "T" << endl; }
// void foo(itn t) { cout << "int" << endl; }
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // T
}
#include <iostream>
using namespace std;
template<typename T>
// void foo(T t) { cout << "T" << endl; }
// void foo(itn t) { cout << "int" << endl; }
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // ...
}
template<typename T>
void foo(T t) { cout << "T" << endl; }
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // T
}
template<typename T>
int foo(T t) { cout << "T" << endl; return 0; }
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // T
}
template<typename T>
typename T::type foo(T t) // int::type foo(int t) - 잘못된 표현이다.
{
cout << "T" << endl;
return 0;
}
void foo(...) { cout << "..." << endl; }
int main()
{
foo(3); // 에러가 나올것인가?
// 에러가 나오지 않고 ...가 호출된다. -> SFINAE
}