#include <string>
#include <memory>
template <class T> struct TInfo;
template <class T> class MyClass;
#define TINFO(type) \
template <> struct TInfo<type> { \
static char const* getName() { \
return #type; \
} \
}; \
typedef MyClass<type> type##_Class; \
typedef std::unique_ptr<MyClass<type>> type##_UPtr;
template <class T>
class MyClass {
private:
std::string m_typeName;
public:
MyClass(std::string objName = "ObjectName")
: m_typeName(std::string(TInfo<T>::getName()) + "_" + objName)
{}
std::string const& getName() {
return m_typeName;
}
};
//usage:
#include <iostream>
TINFO(int);
int main()
{
int_UPtr pi(new int_Class());
std::cout << pi->getName() << '\n';
}
ICAgICNpbmNsdWRlIDxzdHJpbmc+CiAgICAjaW5jbHVkZSA8bWVtb3J5PgogICAgdGVtcGxhdGUgPGNsYXNzIFQ+IHN0cnVjdCBUSW5mbzsKICAgIHRlbXBsYXRlIDxjbGFzcyBUPiBjbGFzcyBNeUNsYXNzOwoKICAgICNkZWZpbmUgVElORk8odHlwZSkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIHRlbXBsYXRlIDw+IHN0cnVjdCBUSW5mbzx0eXBlPiB7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgc3RhdGljIGNoYXIgY29uc3QqIGdldE5hbWUoKSB7ICAgICAgICAgICAgICAgICAgIFwKICAgICAgICByZXR1cm4gI3R5cGU7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIH07ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIHR5cGVkZWYgTXlDbGFzczx0eXBlPiB0eXBlIyNfQ2xhc3M7ICAgICAgICAgICAgICAgIFwKICAgIHR5cGVkZWYgc3RkOjp1bmlxdWVfcHRyPE15Q2xhc3M8dHlwZT4+IHR5cGUjI19VUHRyOyAKICAgIAoKICAgIHRlbXBsYXRlIDxjbGFzcyBUPgogICAgY2xhc3MgTXlDbGFzcyB7CiAgICBwcml2YXRlOgogICAgICBzdGQ6OnN0cmluZyBtX3R5cGVOYW1lOwogICAgCiAgICBwdWJsaWM6CiAgICAgIE15Q2xhc3Moc3RkOjpzdHJpbmcgb2JqTmFtZSA9ICJPYmplY3ROYW1lIikgCiAgICAgICAgOiBtX3R5cGVOYW1lKHN0ZDo6c3RyaW5nKFRJbmZvPFQ+OjpnZXROYW1lKCkpICsgIl8iICsgb2JqTmFtZSkKICAgICAge30KICAgIAogICAgICBzdGQ6OnN0cmluZyBjb25zdCYgZ2V0TmFtZSgpIHsKICAgICAgICByZXR1cm4gbV90eXBlTmFtZTsKICAgICAgfQogICAgfTsKICAgIAogICAgCiAgICAvL3VzYWdlOgogICAgI2luY2x1ZGUgPGlvc3RyZWFtPgogICAgCiAgICBUSU5GTyhpbnQpOwogICAgaW50IG1haW4oKQogICAgewogICAgICBpbnRfVVB0ciBwaShuZXcgaW50X0NsYXNzKCkpOwogICAgICBzdGQ6OmNvdXQgPDwgcGktPmdldE5hbWUoKSA8PCAnXG4nOwogICAgfQ==