-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
70 lines (63 loc) · 1.66 KB
/
Main.cpp
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
68
69
70
//#include "NewBie_Lang.hpp"
//#include "NewBie.hpp"
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <utility>
#include <variant>
#include <any>
using namespace std;
struct helpStruct
{
int type;
void * ptr;
helpStruct(const int &i);
helpStruct(const double &i);
helpStruct(const bool &i);
helpStruct(const std::string &i);
helpStruct(const char * i);
helpStruct(const helpStruct &);
~helpStruct();
template<typename T>
T &get() const
{
return *static_cast<T*>(ptr);
}
};
helpStruct::helpStruct(const int &i) : type(2), ptr(new int(i)) {}
helpStruct::helpStruct(const double &i) : type(3), ptr(new double(i)) {}
helpStruct::helpStruct(const bool &i) : type(4), ptr(new bool(i)) {}
helpStruct::helpStruct(const std::string &i) : type(5), ptr(new string(i)) {}
helpStruct::helpStruct(const char * i) : type(5), ptr(new string(i)) {}
void _print(const vector<helpStruct> & v)
{
for (auto &i : v)
{
switch (i.type)
{
case 2:
cout << "int " << i.get<int>() << endl;
break;
case 3:
cout << "double " << i.get<double>() << endl;
break;
case 4:
cout << "bool " << boolalpha << i.get<bool>() << noboolalpha << endl;
break;
case 5:
cout << "string " << i.get<string>() << endl;
break;
}
}
}
template<typename...Val>
void print(Val&& ...val)
{
_print(vector<helpStruct>{ std::forward<Val>(val)... });
}
int main(int argc, char **argv)
{
print(1, 2, 3, "test");
print(1, "test");
}