fork download
  1. #include <iostream>
  2.  
  3. template<typename T> struct bar { typedef void type; };
  4. template<> struct bar<float> { typedef bar<float> type; };
  5. template<> struct bar<double> { typedef bar<double> type; };
  6.  
  7. template<typename T>
  8. struct foo : bar<T>::type
  9. {
  10. static void func()
  11. {
  12. std::cout << "primary template for float and double" << std::endl;
  13. }
  14. };
  15.  
  16. template<>
  17. struct foo<bool>
  18. {
  19. static void func()
  20. {
  21. std::cout << "specialization for for bool" << std::endl;
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. foo<float>::func();
  28. foo<double>::func();
  29. foo<bool>::func();
  30. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
primary template for float and double
primary template for float and double
specialization for for bool