-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_rep.h
More file actions
45 lines (37 loc) · 861 Bytes
/
debug_rep.h
File metadata and controls
45 lines (37 loc) · 861 Bytes
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
#ifndef DEBUG_REP_H
#define DEBUG_REP_H
#include <string>
#include <sstream>
#include <iostream>
std::string debug_rep(const std::string &s) {
return '"' + s + '"';
}
template <typename T> std::string debug_rep(const T &);
template <typename T> std::string debug_rep(T *);
template <> std::string debug_rep(char *);
template <> std::string debug_rep(const char *);
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();
}
template <>
std::string debug_rep(char *c) {
return debug_rep(std::string(c));
}
template <>
std::string debug_rep(const char *c) {
return debug_rep(std::string(c));
}
#endif