#include <iostream>
#include <typeinfo>
#include <boost/core/demangle.hpp>
template<typename T>
std::string getClassName()
{
return boost::core::demangle(typeid(T).name());
}
struct Test
{
Test()
{
std::cout << "Created instance of " << getClassName<std::decay_t<decltype(*this)>>() << '\n';
}
};
template<typename Derived>
struct IPrintable
{
static std::string getMyName()
{
return getClassName<Derived>();
}
};
struct TestPrintable : IPrintable<TestPrintable>
{
void sayHello() const
{
std::cout << "Hi, I'm " << getMyName() << '\n';
}
};
int main() {
std::cout << getClassName<int>() << '\n';
Test test;
TestPrintable testPrintable;
testPrintable.sayHello();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZWluZm8+CiNpbmNsdWRlIDxib29zdC9jb3JlL2RlbWFuZ2xlLmhwcD4KCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnN0ZDo6c3RyaW5nIGdldENsYXNzTmFtZSgpCnsKCXJldHVybiBib29zdDo6Y29yZTo6ZGVtYW5nbGUodHlwZWlkKFQpLm5hbWUoKSk7Cn0KCnN0cnVjdCBUZXN0CnsKCVRlc3QoKQoJewoJCXN0ZDo6Y291dCA8PCAiQ3JlYXRlZCBpbnN0YW5jZSBvZiAiIDw8IGdldENsYXNzTmFtZTxzdGQ6OmRlY2F5X3Q8ZGVjbHR5cGUoKnRoaXMpPj4oKSA8PCAnXG4nOwoJfQp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgRGVyaXZlZD4Kc3RydWN0IElQcmludGFibGUKewoJc3RhdGljIHN0ZDo6c3RyaW5nIGdldE15TmFtZSgpCgl7CgkJcmV0dXJuIGdldENsYXNzTmFtZTxEZXJpdmVkPigpOwoJfQp9OwoKc3RydWN0IFRlc3RQcmludGFibGUgOiBJUHJpbnRhYmxlPFRlc3RQcmludGFibGU+CnsKCXZvaWQgc2F5SGVsbG8oKSBjb25zdAoJewoJCXN0ZDo6Y291dCA8PCAiSGksIEknbSAiIDw8IGdldE15TmFtZSgpIDw8ICdcbic7Cgl9Cn07CgppbnQgbWFpbigpIHsKCXN0ZDo6Y291dCA8PCBnZXRDbGFzc05hbWU8aW50PigpIDw8ICdcbic7CglUZXN0IHRlc3Q7CglUZXN0UHJpbnRhYmxlIHRlc3RQcmludGFibGU7Cgl0ZXN0UHJpbnRhYmxlLnNheUhlbGxvKCk7CgkKCXJldHVybiAwOwp9