title: Typedef to surrounding type in C++
body: <p>Is there a way to build a <code>typedef</code> inside a type declaration to the declared (surrounding) type itself without stating the type's name?</p>
  
  <p>Example:</p>
  
  <pre><code>class X
  {
    public:
      typedef &lt;fill in magic here&gt; MyType;
    //...
  };
  </code></pre>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>My current solution for g++ defines a static method with return type <code>std::remove_reference(decltype(*this))</code>. (Clang and MSVC do not allow <code>this</code> in the static context).</p>
  
  <p>I would absolutely prefer a standard conform solution but a special solution for clang would also be ok for the moment.</p>
  
  <p>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.</p>
  
  <p><strong>EDIT</strong>: Adding a sample on how the reflection works (which may clarify what I need):</p>
  
  <pre><code>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
  };
  </code></pre>
  
  <p><code>CLASSHEAD</code> is the macro that should define <code>typedef</code>. 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 <code>CLASSHEAD(X, Y)</code> in the example). But I nearly cannot imagine that there is no solution to such a "simply" task as typedef'ing the surrounding type...</p>