#include <iostream>
#include <complex>
template <typename T>
class Vector
{
public:
bool is_complex() { return false; }
};
template <typename U>
class ComplexVector : Vector<std::complex<U>>
{
public:
bool is_complex() { return true; }
bool only_for_complex() { return true; }
};
// For any type T, value is false.
template <typename T>
struct is_complex_vector
{
static const bool value = false;
};
// We specialize the struct so that, for any type U,
// passing ComplexVector<U> makes value true
template <>
template <typename U>
struct is_complex_vector<ComplexVector<U>>
{
static const bool value = true;
};
int main() {
Vector<float> float_vec;
ComplexVector<float> complex_vec;
std::cout << "Is float_vec a ComplexVector type? " << is_complex_vector<typeof(float_vec)>::value << "\n";
std::cout << "Is complex_vec a ComplexVector type? " << is_complex_vector<typeof(complex_vec)>::value << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y29tcGxleD4KCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpjbGFzcyBWZWN0b3IKewogIHB1YmxpYzoKICAgIGJvb2wgaXNfY29tcGxleCgpIHsgcmV0dXJuIGZhbHNlOyB9Cn07Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVT4KY2xhc3MgQ29tcGxleFZlY3RvciA6IFZlY3RvcjxzdGQ6OmNvbXBsZXg8VT4+CnsKICBwdWJsaWM6CiAgICBib29sIGlzX2NvbXBsZXgoKSB7IHJldHVybiB0cnVlOyB9CiAgICBib29sIG9ubHlfZm9yX2NvbXBsZXgoKSB7IHJldHVybiB0cnVlOyB9Cn07CgovLyBGb3IgYW55IHR5cGUgVCwgdmFsdWUgaXMgZmFsc2UuCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpzdHJ1Y3QgaXNfY29tcGxleF92ZWN0b3IKewogICAgc3RhdGljIGNvbnN0IGJvb2wgdmFsdWUgPSBmYWxzZTsKfTsKCi8vIFdlIHNwZWNpYWxpemUgdGhlIHN0cnVjdCBzbyB0aGF0LCBmb3IgYW55IHR5cGUgVSwKLy8gcGFzc2luZyBDb21wbGV4VmVjdG9yPFU+IG1ha2Vz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