2
テンプレートクラスのペアであるenable_if
の実装を理解しようとします。私が理解していないもの、なぜenable_if<true, int>
が最初のものと一致しないのですか?これはどうやって決まるの?テンプレートクラスはどのように一致しますか
#include <iostream>
template <bool, class T = void>
struct enable_if
{
enable_if() { std::cout << "invalid type";}
};
template <class T>
struct enable_if<true, T>
{
typedef T type;
enable_if() { std::cout <<"valid type";}
};
int main(){
enable_if<0==0, int> example; // print "valid type"
return 0;
}
ベストフィットなど。明示的な特殊化を選択することができる場合はそれが適用され、そうでない場合は基本テンプレートがデフォルトになります。 – DeiDei
これは[部分注文](http://en.cppreference.com/w/cpp/language/partial_specialization#Partial_ordering)と呼ばれています。 – Praetorian