title: one #macro add a field and a case (in switch-case)
body: <p>How to define macro (<code>ALL_SWITCH</code>) to recognize another macro (<code>SINGLE_CASE</code>) occurrences as list, and insert codes into 2 different places?    </p>
  
  <p>Is it possible?         </p>
  
  <h2>Example</h2>
  
  <p>I want to create macro that have syntax roughly similar as :-</p>
  
  <pre><code> SINGLE_CASE &lt;Class Name&gt; &lt;Enum slot&gt;  //add fields
   ALL_SWITCH              //recognize all calling SINGLE_CASE (see below)
  </code></pre>
  
  <p>Below is the expected usage.    </p>
  
  <p><strong>TopHeader.h</strong>:-</p>
  
  <pre><code> SINGLE_CASE Machine slot1
   SINGLE_CASE Machine slot2
   //^-------- will be replaced by below code (generate the whole class)
   template&lt;class T&gt; Sloter&lt;Machine&gt; : public GameObject {
       public: int slot1;  
       public: int slot2;          
   };
  
   SINGLE_CASE Turret slot3
   //^-------- will be replaced by below code 
   template&lt;class T&gt; Sloter&lt;Turret&gt;  : public GameObject {
       public: int slot3;            
   };
  </code></pre>
  
  <p><strong>Manager.h</strong>:-</p>
  
  <pre><code> class Manager{
       enum SlotX{ slot1,slot2,slot3 };
       public: int* provider(GameObject* gameObject, SlotX slotX){
           switch(slotX){
               ALL_SWITCH 
               //^---- will be replaced by below code (add only cases)
               case slot1:{ 
                   return &amp;(static_cast&lt;Machine*&gt;(gameObject)-&gt;slot1); 
               }break;
               case slot2:{ 
                   return &amp;(static_cast&lt;Machine*&gt;(gameObject)-&gt;slot2); 
               }break;
               case slot3:{ 
                   return &amp;(static_cast&lt; Turret*&gt;(gameObject)-&gt;slot3); 
               }break;
           }
       }
   };
  </code></pre>
  
  <p>It is not a good design, but it is a simple example to consider whether <code>MACRO</code> can do something <em>aggregate</em>.    </p>
  
  <p>This feature is useful when I really want ultimate performance and flexibility,<br>
  e.g. <a href="https://stackoverflow.com/questions/41562943/datastructure-of-pointers-that-can-removet-addt-and-iterate-really-fast-h">store index into member itself for extremely-fast hashMap</a>.    </p>
  
  <p><strong>I have read :-</strong>    </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5530248/creating-a-string-list-and-an-enum-list-from-a-c-macro">Creating a string list and an enum list from a C++ macro</a><br>
  It is too simple.</li>
  <li><a href="https://stackoverflow.com/questions/4904255/how-can-i-generate-a-list-via-the-c-preprocessor-cpp">How can I generate a list via the C preprocessor (cpp)?</a><br>
  <code>SINGLE_CASE</code> (<code>FUNCTION_TABLE</code> in the solution) contains code, while mine does not.     </li>
  </ul>
  
  <p>I am not sure whether <code>x-macros</code> tag is appropriate.<br>
  (I have limited knowledge in this area.)     </p>
  
  <h2>My progress</h2>
  
  <pre><code>#define SINGLE_CASE( ClassName, slotX) /
  template&lt;class T&gt; Sloter&lt;ClassName&gt; : public GameObject { /
       public: int slotX;  /
  };
  </code></pre>
  
  <p>I still don't know how to make it support many <code>slot</code> for the same class or code <code>ALL_SWITCH</code>.<br>
  I am considering defining some kinds of table in macro, then make other macro read it. (not possible?)</p>