#include <iostream>
#include <typeinfo>

using namespace std;

template <typename T>
class base {
public:
    base (T val = T())
        : m_val(val)
    {}
    base (const base &other)
        : base(other.m_val)
    {}
    virtual void base_specific_method()
    {
        cout << __func__ << " method called: " << m_val << endl;
    }
    void each_class_has_this() {
        cout << __func__ << " this is boring..." << endl;
    }
    T m_val;
};
class other {
public:
    void each_class_has_this() {
        cout << __func__ <<" this is boring..." << endl;
    }
};
class derived_i : public base <int>
{
public:
    derived_i () : base <int> (10)
    {}
    virtual void base_specific_method()
    {
        cout << __func__ <<" Hey! I'm interesting derived! And 10 == " << m_val << endl;
    }
};

template <typename T>
class has_specific
{
    typedef char one;
    typedef long two;

    template <typename C> static one test( typeof(&C::base_specific_method) ) ;
    template <typename C> static two test(...);    

public:
    enum { value = sizeof(test<T>(0)) == sizeof(char) };
};

template <typename T>
class caller {
public:
    caller (T val = T())
        : m_val(val)
    {}
    void call() {
        p_call(m_val);
    }
private:
    template <typename T1=T>
    typename enable_if<!has_specific<T1>::value,void>::type
    p_call (T1 &val)
    {
        val.each_class_has_this();
    }
    template <typename T1=T>
    typename enable_if<has_specific<T1>::value,void>::type
    p_call (T1 &val)
    {
        val.base_specific_method();
    }
private:
    T m_val;
};

int main ()
{
    caller<other> c1;
    caller<base<double> > c2;
    caller<derived_i > c3;

    c1.call();
    c2.call();
    c3.call();
}