fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. enum class enabler {};
  5.  
  6. template <typename T>
  7. using EnableIf = typename std::enable_if<T::value, enabler>::type;
  8. template <typename T>
  9. using DisableIf = typename std::enable_if<!T::value, enabler>::type;
  10.  
  11. template <typename T, EnableIf<std::is_polymorphic<T>> = {}>
  12. void f(T) { std::cout << "is polymorphic\n"; }
  13.  
  14. template <typename T, DisableIf<std::is_polymorphic<T>> = {}>
  15. void f(T) { std::cout << "is not polymorphic\n"; }
  16.  
  17. struct foo { virtual void g() {} };
  18.  
  19. int main() {
  20. f(foo {});
  21. f(int {});
  22. }
  23.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty