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. Y y;
  30. Bar() : data(), y{} { cout << "Bar Specialization" << endl; }
  31. };
  32.  
  33. int main()
  34. {
  35. Bar<Foo<>> a; //matches the specialization with T = template<typename> Foo and Y=int
  36.  
  37. Bar<Baz<float>> b; //matches the specialization with T = template<typename> Baz and Y=float
  38.  
  39. Bar<int> c; //matches the primary template with T=int
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
Foo
Bar Specialization
Baz
Bar Specialization
Bar