Is there a way to build a typedef
inside a type declaration to the declared (surrounding) type itself without stating the type's name?
Example:
class X
{
public:
typedef <fill in magic here> MyType;
//...
};
Background: This seems silly on the first look. I need this because I build compile-time-reflection of my data classes using macros. So there is a macro inserted into the declaration of the data class which needs to deal with the type it is inserted into. So far I found working solutions for MSVC and g++ which both rely on what I think are flaws in the implementation. So they may not work on a newer version. Clang does not "eat" either of these solutions.
My current solution for MSVC defines a method and then takes it's address only by it's name and calls a small helper that "returns" the type of it's class. (Clang and g++ expect the full name of the method including it's class name).
My current solution for g++ defines a static method with return type std::remove_reference(decltype(*this))
. (Clang and MSVC do not allow this
in the static context).
I would absolutely prefer a standard conform solution but a special solution for clang would also be ok for the moment.
If nothing works I have to pass the class' name to the macro but I try to avoid this since I already have plenty of code using the macro.
EDIT: Adding a sample on how the reflection works (which may clarify what I need):
class X : public Y
{
public:
//.. constructor and such stuff...
int a;
double b;
std::string c;
CLASSHEAD(Y)
FIELD(a)
FIELD(b)
FIELD(c)
CLASSFOOT
};
CLASSHEAD
is the macro that should define typedef
. It is a VAR_ARGS macro where the arguments receive the base classes. As said: It is possible to give it the class' name as it's first argument (resulting in CLASSHEAD(X, Y)
in the example). But I nearly cannot imagine that there is no solution to such a "simply" task as typedef'ing the surrounding type...