title: Am I using function pointers correctly?
body: <p>I have a function that looks something like this in pseudocode:</p>
  
  <pre><code>std::string option = "option1" // one of n options, user supplied
  
  for (int i = 0; i &lt; 100000; i++) {
  
      if (option == "option1") {
          doFunction1a();
      } else if (option == "option2") {
          doFunction2a();
      } else if (option == "option3") {
          doFunction3a();
      }
  
      //  more code...
  
      if (option == "option1") {
          doFunction1b();
      } else if (option == "option2") {
          doFunction2b();
      } else if (option == "option3") {
          doFunction3b();
      }
  
  }
  </code></pre>
  
  <p>However, I could avoid the repeated if statement inside the loop by doing something like this:</p>
  
  <pre><code>std::string option = "option1" // one of n options, user supplied
  
  int (*doFunctiona)(int, int);
  int (*doFunctionb)(int, int);
  
  if (option == "option1") {
      doFunctiona = doFunction1a;
      doFunctionb = doFunction1b;
  } else if (option == "option2") {
      doFunctiona = doFunction2a;
      doFunctionb = doFunction2b;
  } else if (option == "option3") {
      doFunctiona = doFunction3a;
      doFunctionb = doFunction3b;
  }
  
  for (int i = 0; i &lt; 100000; i++) {
  
      doFunctiona();
  
      //  more code...
  
      doFunctionb();
  
  }
  </code></pre>
  
  <p>I realize that this will have little effect on performance (the time spend by the functions dominates the time it takes to execute the if statement). </p>
  
  <p>However, In terms of "good coding practices", is this a good way to set up variable function calling? With "good" I mean: (1) easily expandable, there could easily be 20 options in the future; 2) results in readable code. I'm hoping there exists some kind of standard method for accomplishing this. If not, feel free to close as opinion based.</p>