#include <iostream>
using namespace std;
template <typename T = int>
struct Foo {
T t;
Foo() { cout << "Foo" << endl; }
};
template <typename T>
struct Baz {
T t;
Baz() { cout << "Baz" << endl; }
};
template <typename T>
struct Bar {
T t;
Bar() { cout << "Bar" << endl; }
};
template <template <typename > class T,class Y>
struct Bar<T<Y>>
{
T<Y> data;
Y y;
Bar() : data(), y{} { cout << "Bar Specialization" << endl; }
};
int main()
{
Bar<Foo<>> a; //matches the specialization with T = template<typename> Foo and Y=int
Bar<Baz<float>> b; //matches the specialization with T = template<typename> Baz and Y=float
Bar<int> c; //matches the primary template with T=int
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdGVtcGxhdGUgPHR5cGVuYW1lIFQgPSBpbnQ+CnN0cnVjdCBGb28gewogICAgVCB0OwogICAgRm9vKCkgeyBjb3V0IDw8ICJGb28iIDw8IGVuZGw7IH0KfTsKIAp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4Kc3RydWN0IEJheiB7CiAgICBUIHQ7CiAgICBCYXooKSB7IGNvdXQgPDwgIkJheiIgPDwgZW5kbDsgfQp9OwogCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpzdHJ1Y3QgQmFyIHsKICAgIFQgdDsKICAgIEJhcigpIHsgY291dCA8PCAiQmFyIiA8PCBlbmRsOyB9Cn07CiAKIAogCnRlbXBsYXRlIDx0ZW1wbGF0ZSA8dHlwZW5hbWUgPiBjbGFzcyBULGNsYXNzIFk+CnN0cnVjdCBCYXI8VDxZPj4gCnsKICAgIFQ8WT4gZGF0YTsKICAgIFkgeTsKICAgIEJhcigpIDogZGF0YSgpLCB5e30geyBjb3V0IDw8ICJCYXIgU3BlY2lhbGl6YXRpb24iICA8PCBlbmRsOyB9Cn07CiAKaW50IG1haW4oKQp7CiAgICBCYXI8Rm9vPD4+IGE7IC8vbWF0Y2hlcyB0aGUgc3BlY2lhbGl6YXRpb24gd2l0aCBUID0gdGVt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