fork download
  1. #include <boost/type_traits.hpp>
  2. #include <boost/utility.hpp>
  3. #include <iostream>
  4. #include <ostream>
  5.  
  6. using namespace std;
  7.  
  8. struct Base1 {};
  9. struct Derived1 : Base1 {};
  10.  
  11. struct Base2 {};
  12. struct Derived2 : Base2 {};
  13.  
  14. template<typename T>
  15. typename boost::enable_if< boost::is_base_of<Base1, T>, void >::type f(T* p)
  16. {
  17. cout << "Base1" << endl;
  18. }
  19.  
  20. template<typename T>
  21. typename boost::enable_if< boost::is_base_of<Base2, T>, void >::type f(T* p)
  22. {
  23. cout << "Base2" << endl;
  24. }
  25.  
  26. int main()
  27. {
  28. Derived1 d1;
  29. Derived2 d2;
  30. f(&d1);
  31. f(&d2);
  32. }
  33.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
Base1
Base2