language: C++ 4.7.2 (gcc-4.7.2)
date: 651 days 18 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
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <typeinfo>
using namespace std;
 
 
template <typename Super> class A : public Super {};
 
template <typename Super> class B : public Super {};
 
template <typename Super> class C : public Super {};
 
class Blank{};
 
//----------------------------------------
 
struct null{};
 
template<typename> 
struct split
{
   typedef null Ct;
   typedef null At;
};
 
template<template<typename> class C, typename T> 
struct split<C<T> >
{
   typedef C<null> Ct; //class template 
   typedef T      At;  //argument type
};
 
template<template<typename> class C> 
struct split<C<Blank> >
{
   typedef C<null> Ct; //class template 
   typedef Blank   At;  //argument type
};
 
template<typename T, typename U>
struct is_same
{
   static const bool value = false;
};
template<typename T>
struct is_same<T,T>
{
   static const bool value = true;
};
 
typedef  A<null> anull;
typedef  B<null> bnull;
typedef  C<null> cnull;
 
//----------------------------------------
 
template <typename CombinedType>
void printTypeComponents(const CombinedType & t)
{
     typedef typename split<CombinedType>::Ct Ct;
     typedef typename split<CombinedType>::At At;
 
     if ( is_same<Ct,anull>::value ) 
           cout << "A" << endl;
     else if ( is_same<Ct,bnull>::value )
           cout << "B" << endl;
     else if ( is_same<Ct,cnull>::value )
           cout << "C" << endl;
 
     if ( !is_same<At,Blank>::value )
           printTypeComponents(At());
     else
           cout << "Blank" << endl;
}
int main()
{
     typedef A<B<C<Blank> > > ComposedType;
     ComposedType ct;
     printTypeComponents(ct);
 
     cout<<"-------"<<endl;
 
     typedef A<C<Blank> > ComposedType2;
     ComposedType2 ct2;
     printTypeComponents(ct2);
}