#include <type_traits> class A {};class B : A {};class C : A {};class X{}; template<typename T>class D{ static_assert(std::is_base_of<A,T>::value, "T must be derived from A");}; int main(){ D<C> d_valid; D<X> d_fails; // compilation fails return 0;}
Standard input is empty
prog.cpp: In instantiation of 'class D<X>': prog.cpp:17:10: required from here prog.cpp:11:5: error: static assertion failed: T must be derived from A static_assert(std::is_base_of<A,T>::value, "T must be derived from A"); ^
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!