language: C++ 4.7.2 (gcc-4.7.2)
date: 648 days 22 hours ago
link:
visibility: public
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
74
#include <iostream>
#include <typeinfo>
#include <cxxabi.h> // for demangle
#include <stdlib.h> // for free
#include <string>
 
template <typename Super>
class A : public Super
{ };
 
template <typename Super>
class B : public Super
{ };
 
template <typename Super>
class C : public Super
{ };
 
namespace SomeCrazyNamespace {
 
template <typename Super>
class SomeCrazyClassName : public Super
{ };
 
}
 
class Blank
{ };
 
std::string getTemplateName(std::string arg)
// won't work for classes nested inside template class,
// this is just for sake of example
{
  arg.resize(arg.find_first_of('<'));
  return arg;
}
 
void printTypeComponents(const Blank&)
{
  std::cout << "composed of Blank\n";
}
 
template <template <typename> class Q, typename T>
void printTypeComponents(const Q<T>&)
{
  int status;
  char* realname = abi::__cxa_demangle(typeid(Q<Blank>).name(), 0, 0, &status);
 
  std::cout << "composed of " << getTemplateName(realname) << '\n';
  free(realname);
  
  printTypeComponents(T());
}
 
 
int main()
{
  typedef A<B<C<Blank> > > ComposedType;
  ComposedType ct;
  printTypeComponents(ct);
  
  std::cout << '\n';
 
  typedef A<C<Blank> > ComposedType2;
  ComposedType2 ct2;
  printTypeComponents(ct2);
  
  std::cout << '\n';
  
  typedef SomeCrazyNamespace::SomeCrazyClassName<A<Blank> > ComposedType3;
  ComposedType3 ct3;
  printTypeComponents(ct3);
}