title: C++ switch - preprocessed case arguments?
body: <p>In my switch I want the cases to go from 0 to the (<code>number_of_cases-1</code>), without writing the numbers myself. So that if I delete one case block in the middle, the following cases would renumber (decrement by 1), so that the switch again is from (<code>0..caseNo-1</code>).</p>
  
  <p>Like this (of course it won't compile, as the <code>i++</code> aren't known compile time):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #define ALWAYS_SECOND_CASE 1
  
  void nop(char c){}
  
  int main()
  {
   int i=0;
   int var=ALWAYS_SECOND_CASE;
  
   switch(var)
   {
    case i++: //case 0:
      nop('x');
      break;
    case i++: //case 1:
      nop('y')
      break;
    case i++: //case 2:
      nop('z')
      break;
   }
  
   //case 1 should have been switched to, nop('y') called.
  }
  </code></pre>
  
  <p>Now I delete the middle case, and without writing anything the last case should change from case 2 to case 1:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #define ALWAYS_SECOND_CASE 1
  
  void nop(char c){}
  
  int main()
  {
   int i=0;
   int var=ALWAYS_SECOND_CASE;
  
   switch(var)
   {
    case i++: //case 0:
      nop('x');
      break;
    case i++: //case 1: instead of case 2 like before
      nop('z')
      break;
   }
  
   //case 1 should have been switched to, nop('z') called,
   // instead of nop('y') like before.
  }
  </code></pre>
  
  <p>So I can't use variables, as they are too variable; then symbolic constants are too constant, I can do <code>SYMC+1</code>, but no <code>SYMC++</code>. So maybe enums, or some nice macro function?</p>
  
  <p>EDIT
  Thanks for the if-else hint, I just thought that since the case values are known compile-time it would be nicer to use the switch..</p>
  
  <p>And to specify what I want to do: I have a menu <code>char[rows][cols]={"first line","second line"}</code>. I want to map the switch cases to the lines, so that if I want to remove a line from the menu (which decrements following line numbers), I will just remove one single case in the rest of the program.</p>