"type == type"をテストするクラスを作成しますが、typeに演算子がない場合は失敗します。コンパイル時にタイプに "bool operator ==(const type&、const type&)"というウェイテストがありますか?
template <typename _Type>
double _test(...){
return 0;
}
template <typename _Type>
auto _test(_Type&& t)->decltype(t == t){
return 0;
}
template <typename _Type>
struct has_equal_to
{
static const bool value = sizeof(_test(std::declval<_Type>())) == sizeof(char);
};
struct test{};
int main()
{
std::cout << has_equal_to<test>::value << std::endl; // compile failed ~~~~
return 1;
}
誰でも手伝ってもらえますか? それとも、このようなクラスを記述することは不可能である.....
私は信じられるかもしれません。 http://en.cppreference.com/w/cpp/language/sfinaeを参照してください。私はこれを解決する賢明な回答者をupvoteよ! – Bathsheba
'sizeof(char)'は正しいですか? 'sizeof(ブール)'確かに? –
私は同じ質問が既に存在すると思います。http://stackoverflow.com/questions/6534041/how-to-check-whether-operator-exists? – Shrikant