language: C++ 4.7.2 (gcc-4.7.2)
date: 199 days 4 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
#include <iostream>
 
using namespace std;
 
template <typename T>
class Base
{
    public:
        T* t;
        void b() {}
};
 
class D1:
        public Base<D1>
{
    public:
        int d1;
};
 
class D2:
        public D1
{
    public:
        int d2;
};
 
template<template<typename> class Base, typename T>
struct IsAnyPublicBaseOf
{
  typedef char (&yes)[2];
 
  template<typename X>
  static yes Check (Base<X>*);
  static char Check (...);
 
  static const bool value = (sizeof(Check((T*)0)) == sizeof(yes));
};
 
template<bool> struct Bool;
template <typename T, typename = Bool<true> >
class Selector
{
public:
  template <typename U>
  void a(U& u)
  {
    cout << "a(U&)" << endl;
  }
};
 
template<typename T>
class Selector<T,Bool<IsAnyPublicBaseOf<Base,T>::value> >
{
public:
  template <typename U>
  void a(Base<U>& base)
  {
    cout << "a(Base<U>&)" << endl;
    base.b();
  }
};
 
 
int main()
{
    D2 derivated;
    Selector<D2> s;
    s.a(derivated);
    return 0;
}