-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path16.48.cpp
55 lines (48 loc) · 1.04 KB
/
16.48.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
#include<iostream>
#include<string>
#include<sstream>
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 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));
}
int main()
{
std::string s("hi");
std::string * sp = &s;
std::cout << debug_rep(s) << std::endl;
std::cout << debug_rep(&s) << std::endl;
std::cout << debug_rep(sp) << std::endl;
std::cout << debug_rep("hi world!") << std::endl;
return 0;
}