#include <iostream>
#include <type_traits>
#include <vector>
class ThingBase {
public :
virtual void printHi( ) = 0 ;
} ;
class Thing : public ThingBase
{
void printHi( ) {
std:: cout << "hi\n " ;
}
} ;
template < typename ThingType>
class Container{
private :
std:: vector < ThingType> m_things;
public :
typename std:: enable_if < std:: is_base_of < ThingBase, ThingType> :: value > :: type p( )
{
m_things[ 0 ] .printHi ( ) ;
} ;
} ;
int main( ) {
//Container<Thing> stuff; // works!
Container< int > stuff; // doesn't work :(
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CiNpbmNsdWRlIDx2ZWN0b3I+CgoKY2xhc3MgVGhpbmdCYXNlIHsKcHVibGljOgoJdmlydHVhbCB2b2lkIHByaW50SGkoKSA9IDA7CgkKfTsKCmNsYXNzIFRoaW5nIDogcHVibGljIFRoaW5nQmFzZQp7Cgl2b2lkIHByaW50SGkoKXsKCQlzdGQ6OmNvdXQgPDwgImhpXG4iOwoJfQkKfTsKCgp0ZW1wbGF0ZTx0eXBlbmFtZSBUaGluZ1R5cGU+CmNsYXNzIENvbnRhaW5lcnsKcHJpdmF0ZToKCXN0ZDo6dmVjdG9yPFRoaW5nVHlwZT4gbV90aGluZ3M7CnB1YmxpYzoKCgl0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZjxzdGQ6OmlzX2Jhc2Vfb2Y8VGhpbmdCYXNlLCBUaGluZ1R5cGU+Ojp2YWx1ZT46OnR5cGUgcCgpCgl7CgkJbV90aGluZ3NbMF0ucHJpbnRIaSgpOwoJfTsKfTsKCgppbnQgbWFpbigpIHsKCQoJLy9Db250YWluZXI8VGhpbmc+IHN0dWZmOyAvLyB3b3JrcyEKCUNvbnRhaW5lcjxpbnQ+IHN0dWZmOyAvLyBkb2Vzbid0IHdvcmsgOigKCQoJcmV0dXJuIDA7Cn0=
compilation info
prog.cpp: In instantiation of ‘class Container<int>’:
prog.cpp:36:17: required from here
prog.cpp:26:78: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
typename std::enable_if<std::is_base_of<ThingBase, ThingType>::value>::type p()
^
stdout