fork download
  1. #include <type_traits>
  2.  
  3. struct A {};
  4. struct B : A {};
  5. struct C;
  6.  
  7. template <typename T>
  8. struct Template {};
  9.  
  10.  
  11. template <typename T>
  12. void foo(const Template<T*>& tc) {
  13. static_assert(std::is_convertible<T*, A*>::value, "Template argument must be convertible to A*");
  14. }
  15.  
  16. int main() {
  17. Template<A*> a;
  18. Template<B*> b;
  19. Template<C*> c;
  20.  
  21. foo(a);
  22. foo(b);
  23. foo(c);
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void foo(const Template<T*>&) [with T = C]':
prog.cpp:23:7:   instantiated from here
prog.cpp:13:2: error: static assertion failed: "Template argument must be convertible to A*"
stdout
Standard output is empty