Skip to content

Instantly share code, notes, and snippets.

@utilForever
Last active December 6, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/cfade41a1b9e5f16cef91af67386f8e6 to your computer and use it in GitHub Desktop.
Save utilForever/cfade41a1b9e5f16cef91af67386f8e6 to your computer and use it in GitHub Desktop.
Left Join
#include <iostream>
#include <string>
#include <map>
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
# include <cxxabi.h>
#endif
#include <memory>
#include <string>
#include <cstdlib>
template <class T>
std::string
type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void(*)(void*)> own
(
#ifndef _MSC_VER
abi::__cxa_demangle(typeid(TR).name(), nullptr,
nullptr, nullptr),
#else
nullptr,
#endif
std::free
);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
std::map<std::string, std::string> g_symTable;
#define NAME_OF(v) #v
#define TYPE_OF(v) type_name<decltype(v)>()
#define ATTRIBUTE(type, name) \
type name##_; \
public: \
const type& get_##name() const { return name##_; } \
void set_##name(const type& v) { name##_ = v; }
#define DECLARE_CLASS(class_name) \
class class_name \
{ \
ATTRIBUTE(int, bla); \
ATTRIBUTE(double, v); \
};
struct A
{
int value;
std::string name;
public:
A(int _value, std::string _name) :
value(_value), name(_name)
{
g_symTable.insert(std::make_pair(NAME_OF(value), TYPE_OF(value)));
g_symTable.insert(std::make_pair(NAME_OF(name), TYPE_OF(name)));
}
};
struct B
{
int value;
int money;
public:
B(int _value, int _money) :
value(_value), money(_money)
{
g_symTable.insert(std::make_pair(NAME_OF(value), TYPE_OF(value)));
g_symTable.insert(std::make_pair(NAME_OF(money), TYPE_OF(money)));
}
};
int main()
{
A a[] = { { 10, "AAA" }, { 20, "BBB" } };
B b[] = { { 20, 100 }, { 30, 200 } };
for (auto elem : g_symTable)
{
std::cout << elem.first << " : " << elem.second << std::endl;
}
DECLARE_CLASS(C);
C c;
c.set_bla(30);
std::cout << c.get_bla() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment