#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; }
};
int main() {
Vector<float> float_vec;
ComplexVector<float> complex_vec;
std::cout << "Is float_vec complex? " << float_vec.is_complex() << "\n";
std::cout << "Is complex_vec complex? " << complex_vec.is_complex() << "\n";
// The following line doesn't compile
// std::cout << "Is only_for_complex method in float_vec? " << float_vec.only_for_complex() << "\n";
std::cout << "Is only_for_complex method in complex_vec? " << complex_vec.only_for_complex() << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y29tcGxleD4KCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpjbGFzcyBWZWN0b3IKewogIHB1YmxpYzoKICAgIGJvb2wgaXNfY29tcGxleCgpIHsgcmV0dXJuIGZhbHNlOyB9Cn07Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVT4KY2xhc3MgQ29tcGxleFZlY3RvciA6IFZlY3RvcjxzdGQ6OmNvbXBsZXg8VT4+CnsKICBwdWJsaWM6CiAgICBib29sIGlzX2NvbXBsZXgoKSB7IHJldHVybiB0cnVlOyB9CiAgICBib29sIG9ubHlfZm9yX2NvbXBsZXgoKSB7IHJldHVybiB0cnVlOyB9Cn07CgppbnQgbWFpbigpIHsKICBWZWN0b3I8ZmxvYXQ+IGZsb2F0X3ZlYzsKICBDb21wbGV4VmVjdG9yPGZsb2F0PiBjb21wbGV4X3ZlYzsKICAKICBzdGQ6OmNvdXQgPDwgIklzIGZsb2F0X3ZlYyBjb21wbGV4PyAiIDw8IGZsb2F0X3ZlYy5pc19jb21wbGV4KCkgPDwgIlxuIjsKICBzdGQ6OmNvdXQgPDwgIklzIGNvbXBsZXhfdmVjIGNvbXBsZXg/ICIgPDwgY29tcGxleF92ZWMuaXNfY29tcGxleCgpIDw8ICJcbiI7CiAgCiAgLy8gVGhlIGZvbGxvd2luZ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