-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path16.56.cpp
74 lines (64 loc) · 1.62 KB
/
16.56.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
71
72
73
#include<iostream>
#include<string>
#include<sstream>
template <typename T> std::ostream & print(std::ostream & os, const T & t);
template <typename T, typename ... Args> std::ostream & print(std::ostream & os, const T & t, const Args & ... rest);
template <typename T> std::string debug_rep(const T &t);
template <typename T> std::string debug_rep(T * p);
std::string debug_rep(const std::string &s);
std::string debug_rep(char *p);
std::string debug_rep(const char *p);
template <typename ... Args> std::ostream & errorMsg(std::ostream & os, const Args & ... rest);
template <typename T>
std::ostream & print(std::ostream & os, const T & t)
{
return os << t;
}
template <typename T, typename ... Args>
std::ostream & print(std::ostream & os, const T & t, const Args & ... rest)
{
os << t << ", ";
return print(os, rest...);
}
template <typename T>
std::string debug_rep(const T &t)
{
std::ostringstream ret;
ret << t;
return ret.str();
}
template <typename T>
std::string debug_rep(T * p)
{
std::ostringstream ret;
ret << "pointer: " << p;
if(p)
ret << " " << debug_rep(*p);
else
ret << " null pointer";
return ret.str();
}
std::string debug_rep(const std::string &s)
{
return '"' + s + '"';
}
std::string debug_rep(char *p)
{
return debug_rep(std::string(p));
}
std::string debug_rep(const char *p)
{
return debug_rep(std::string(p));
}
template <typename ... Args>
std::ostream & errorMsg(std::ostream & os, const Args & ... rest)
{
return print(os, debug_rep(rest)...);
}
int main()
{
int i = 3;
errorMsg(std::cout, 1, "123", std::string("qwer"), &i) << std::endl;
errorMsg(std::cout, 1) << std::endl;
return 0;
}