fork download
  1. #include <iostream>
  2.  
  3. struct foo1 { };
  4. struct foo2 { typedef int bar; };
  5.  
  6. template<typename T>
  7. void dispatch_impl(...)
  8. {
  9. std::cout << "default target\n";
  10. }
  11.  
  12. template<typename T>
  13. void dispatch_impl(typename T::bar*)
  14. {
  15. std::cout << "specialized target\n";
  16. }
  17.  
  18. template<typename T>
  19. void dispatch()
  20. {
  21. dispatch_impl<T>(0);
  22. }
  23.  
  24. int main()
  25. {
  26. dispatch<foo1>();
  27. dispatch<foo2>();
  28. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
default target
specialized target