-
Notifications
You must be signed in to change notification settings - Fork 0
/
Type To Type.h
67 lines (38 loc) · 842 Bytes
/
Type To Type.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#pragma once
#include<string>
namespace tp_to_type {
class Widget {
int some_required_value;
std::string widget_name;
public:
Widget(int some_required_value, std::string widget_name) :some_required_value(some_required_value), widget_name(widget_name) {}
auto getName() const {
return widget_name;
}
};
class TERA {
std::string name;
public:
TERA(std::string name) :name(name) {}
auto getName() const {
return name;
}
};
template<typename T>
struct type_to_type {
typedef T value_type;
};
template<unsigned n>
struct int2type {
enum{value=n};
};
template<typename T, typename U>
T* create(const U& arg, type_to_type<T>) {
return new T(arg);
}
template<typename U>
Widget* create(const U& arg, type_to_type<Widget>) {
return new Widget(-1, arg);
}
}