fork download
  1. #include <iostream>
  2.  
  3. class A{};
  4. class B : A{};
  5. class C{};
  6.  
  7. template <typename T>
  8. void f (T t) {
  9. static_assert (
  10. std::is_same<T, A>::value || std::is_base_of<A, T>::value,
  11. "Type must be either A or derived from A."
  12. );
  13.  
  14. std::cout << "Yay";
  15. }
  16.  
  17. int main() {
  18. A a;
  19. B b;
  20. C c;
  21. f(c);
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void f(T) [with T = C]':
prog.cpp:21:8:   instantiated from here
prog.cpp:9:5: error: static assertion failed: "Type must be either A or derived from A."
stdout
Standard output is empty