-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnamer.h
More file actions
69 lines (57 loc) · 1.48 KB
/
namer.h
File metadata and controls
69 lines (57 loc) · 1.48 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
68
69
#ifndef COOL_THINGS_NAMER_H
#define COOL_THINGS_NAMER_H
#include <string>
#include <type_traits>
#include <vector>
// Base case -- use the typeid facility to produce the name
// of the type. This potentially produces ugly names for basic
// types like 'int'.
template <typename T>
struct namer
{
static std::string name() { return typeid(T).name(); }
};
// Specialization to return a decent type name for 'int'
template <>
struct namer<int>
{
static std::string name() { return "int"; }
};
template <>
struct namer<std::string>
{
static std::string name() { return "std::string"; }
};
// More declarations for other primitive types should follow
template <typename...>
struct typelist_to_namelist;
template <typename T>
struct typelist_to_namelist<T>
{
static std::string namelist() { return namer<T>::name(); }
};
template <typename T, typename... Ts>
struct typelist_to_namelist<T, Ts...>
{
static std::string namelist()
{
return typelist_to_namelist<T>::namelist() + ", " + typelist_to_namelist<Ts...>::namelist();
}
};
template <typename... Ts>
struct namer<std::vector<Ts...>>
{
static std::string name()
{
std::string name("std::vector<");
name += typelist_to_namelist<Ts...>::namelist();
return name + ">";
}
};
template <typename... Ts>
struct namer<std::allocator<Ts...>>
{
static std::string name() { return "std::allocator"; }
};
// More declarations for other containers should follow
#endif //COOL_THINGS_NAMER_H