#include <iostream>
template <class T, typename U = void> class A;
template <class T>
class C
{
public:
typedef T Var_t;
};
template <class T>
class B : public C<T>
{
};
template <class T>
class A<B<T>>
{
public:
A() { std::cout << "Here." << std::endl; }
};
template <class T>
class A<T, typename std::enable_if<
std::is_base_of<C<typename T::Var_t>, T>::value>
//true>
::type>
{
public:
A() { std::cout << "There." << std::endl;}
};
int main()
{
A<B<int>> a;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPGNsYXNzIFQsIHR5cGVuYW1lIFUgPSB2b2lkPiBjbGFzcyBBOwoKdGVtcGxhdGUgPGNsYXNzIFQ+CmNsYXNzIEMKewpwdWJsaWM6Cgl0eXBlZGVmIFQgVmFyX3Q7Cn07Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4KY2xhc3MgQiA6IHB1YmxpYyBDPFQ+CnsKfTsKCnRlbXBsYXRlIDxjbGFzcyBUPgpjbGFzcyBBPEI8VD4+CnsKcHVibGljOgoJQSgpIHsgc3RkOjpjb3V0IDw8ICJIZXJlLiIgPDwgc3RkOjplbmRsOyB9Cn07Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4KY2xhc3MgQTxULCB0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZjwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGQ6OmlzX2Jhc2Vfb2Y8Qzx0eXBlbmFtZSBUOjpWYXJfdD4sIFQ+Ojp2YWx1ZT4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL3RydWU+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgOjp0eXBlPgp7CnB1YmxpYzoKCUEoKSB7IHN0ZDo6Y291dCA8PCAiVGhlcmUuIiA8PCBzdGQ6OmVuZGw7fQp9OwoKaW50IG1haW4oKSAKewoJQTxCPGludD4+IGE7CglyZXR1cm4gMDsKfQ==
prog.cpp: In function ‘int main()’:
prog.cpp:36:12: error: ambiguous template instantiation for ‘class A<B<int> >’
A<B<int>> a;
^
prog.cpp:18:7: note: candidates are: template<class T> class A<B<T> > [with T = int]
class A<B<T>>
^~~~~~~
prog.cpp:25:7: note: template<class T> class A<T, typename std::enable_if<std::is_base_of<C<typename T::Var_t>, T>::value>::type> [with T = B<int>]
class A<T, typename std::enable_if<
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
std::is_base_of<C<typename T::Var_t>, T>::value>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//true>
~~~~~~~
::type>
~~~~~~~
prog.cpp:36:12: error: aggregate ‘A<B<int> > a’ has incomplete type and cannot be defined
A<B<int>> a;
^