forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSFINAE.cpp
More file actions
41 lines (33 loc) · 692 Bytes
/
SFINAE.cpp
File metadata and controls
41 lines (33 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Created by light on 20-1-5.
//
#include <iostream>
using namespace std;
template<typename T>
class IsClassT {
private:
typedef char One;
typedef struct {
char a[2];
} Two;
template<typename C>
static One test(int C::*);
// Will be chosen if T is anything except a class.
template<typename C>
static Two test(...);
public:
enum {
Yes = sizeof(IsClassT<T>::test<T>(0)) == 1
};
enum {
No = !Yes
};
};
struct A {
};
int main() {
// 0不能转换为int int::*因为int不是类,所以它不能有成员指针。
cout << IsClassT<int>::Yes << endl;
cout << IsClassT<A>::Yes << endl;
return 0;
}