title: Better alternatives for switch statements
body: <p>I know that this has been already discussed, and there are multiple answers to it. See <a href="https://stackoverflow.com/questions/5582261/performance-of-array-of-functions-over-if-and-switch-statements">Performance of array of functions over if and switch statements</a> for instance, however I would like to get some other ideas.</p>
  
  <p>I've got a function with a large <code>switch</code> statement. This is 26 <code>case</code> and each with a "left" or "right" option. This function returns a pointer based on two given parameters (<code>plane</code> and <code>direction</code>):</p>
  
  <pre><code>double* getPointer(int plane, int direction) {
    switch (plane)
    {
    case 0:
      if (direction == 0)
        return  p_YZ_L; // Left
      else if (dir == 1)
        return p_YZ_R;  //Right
      else {
        return 0;
      }
  
      break;
      ...
    case 25:
      ...
    }
  }
  </code></pre>
  
  <p>with</p>
  
  <pre><code>planes -&gt; [0-25]
  direction -&gt; [0,1] 
  </code></pre>
  
  <p>I have been thinking on an array of functions, but this could also be tedious and I am not sure if it is the best option. Also it is not clear to me how to do it properly. Any ideas?</p>