Is it possible to write a trait, which results the type of the class it is used in? How to implement get_class in the example below?
class Foo {
typedef get_class::type type; // type = Foo now
};
Note: I have to write a macro, which expands in the class body, used for multiple classes, so I cannot simply write 'typedef Foo type;'
Use case:
I have a reflectable(...) macro which generates infrastructure to iterate over members, visit them and look them up using their names:
class Foo
{
friend std::ostream &operator<<(std::ostream &, const Foo&);
reflectable(
(int) bar,
(double) baz
)
}
reflectable(...) should be a macro so I can get the types and member names separately as strings to build maps for the lookup.
I would like all reflectable class to be streamable, but if I put my reflectable() macro to private section, I have to add the friend declaration to the class. I would like to move it to the macro as:
friend std::ostream &operator<<(std::ostream &, const get_class::type&);