fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T = int>
  6. struct Foo {
  7. T t;
  8. Foo() { cout << "Foo" << endl; }
  9. };
  10.  
  11. template <typename T>
  12. struct Baz {
  13. T t;
  14. Baz() { cout << "Baz" << endl; }
  15. };
  16.  
  17. template <typename T>
  18. struct Bar {
  19. T t;
  20. Bar() { cout << "Bar" << endl; }
  21. };
  22.  
  23.  
  24.  
  25. template <template <typename > class T,class Y>
  26. struct Bar<T<Y>>
  27. {
  28. T<Y> data;
  29. Bar() : data() { cout << "Bar Specialization" << endl; }
  30. };
  31.  
  32. int main()
  33. {
  34. Bar<Foo<>> a; //matches the specialization with T = template<typename> Foo and Y=int
  35.  
  36. Bar<Baz<float>> b; //matches the specialization with T = template<typename> Baz and Y=float
  37.  
  38. Bar<int> c; //matches the primary template with T=int
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Foo
Bar Specialization
Baz
Bar Specialization
Bar