-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.09.cpp
More file actions
67 lines (61 loc) · 1.84 KB
/
19.09.cpp
File metadata and controls
67 lines (61 loc) · 1.84 KB
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
#include <typeinfo>
#include <iostream>
#include <string>
#include <map>
#include "Sales_data.h"
class Base {};
class Derived : public Base {};
using std::cout;
using std::endl;
using std::map;
std::string translate(const std::string &name) {
static const map<std::string, std::string> trans_list {
{"i", "int"},
{"A10_i", "array of ints of size 10"},
{"10Sales_data", "Sales_data"},
{"NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", "std::string"},
{"P4Base", "Base *"},
{"4Base", "Base"},
{"c", "char"},
{"j", "unsigned"},
{"s", "short"},
{"t", "unsigned short"},
{"h", "unsigned char"},
{"a", "signed char"},
{"l", "long"},
{"x", "long long"},
{"m", "unsigned long"},
{"y", "unsigned long long"},
{"f", "float"},
{"d", "double"},
{"b", "bool"}
};
if (trans_list.count(name))
return trans_list.at(name);
return name;
}
int main() {
int arr[10];
Derived d;
Base *p = &d;
cout << translate(typeid(42).name()) << ",\n"
<< translate(typeid(arr).name()) << ",\n"
<< translate(typeid(Sales_data).name()) << ",\n"
<< translate(typeid(std::string).name()) << ",\n"
<< translate(typeid(p).name()) << ",\n"
<< translate(typeid(*p).name()) << ",\n"
<< translate(typeid(char).name()) << ",\n"
<< translate(typeid(unsigned).name()) << ",\n"
<< translate(typeid(short).name()) << ",\n"
<< translate(typeid(unsigned short).name()) << ",\n"
<< translate(typeid(unsigned char).name()) << ",\n"
<< translate(typeid(signed char).name()) << ",\n"
<< translate(typeid(long).name()) << ",\n"
<< translate(typeid(long long).name()) << ",\n"
<< translate(typeid(unsigned long).name()) << ",\n"
<< translate(typeid(unsigned long long).name()) << ",\n"
<< translate(typeid(float).name()) << ",\n"
<< translate(typeid(double).name()) << ",\n"
<< translate(typeid(bool).name()) << endl;
return 0;
}