Skip to content

Instantly share code, notes, and snippets.

@FONQRI
Created April 12, 2019 10:33
Show Gist options
  • Save FONQRI/74b778490330234f795a5b2f6f133ea8 to your computer and use it in GitHub Desktop.
Save FONQRI/74b778490330234f795a5b2f6f133ea8 to your computer and use it in GitHub Desktop.
Define name string with macro and iit it with class name.
#include <boost/type_index.hpp>
#include <iostream>
#define DEFINE_NAME \
std::string name \
{ \
boost::typeindex::type_id<decltype(*this)>().pretty_name() \
};
class Test2
{
public:
DEFINE_NAME
};
int main()
{
Test2 t;
std::clog << t.name << std::endl; // human readable
return 0;
}
//output :
// Test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment