title: conditional line-by-line reading from file
body: <p>For now I have that code:</p>
  
  <pre><code>if (minimizator_weighted) {
      while (dataFile &gt;&gt; t &gt;&gt; e &gt;&gt; sigma) { // read data file value by value
          /* some code */
      }
  }
  else {
      while (dataFile &gt;&gt; t &gt;&gt; e) { // all the same but will not read standard deviation
          /* almost the same code */
      }
  }
  </code></pre>
  
  <p>As you can see the only difference between <code>if</code> and <code>else</code> flows is the condition of <code>while</code> loop. I wonder if there any possibility to optimize that snippet and re-use the code? It would be great if I could write some kind of:</p>
  
  <pre><code>while ((minimizator_weighted) ? (dataFile &gt;&gt; t &gt;&gt; e &gt;&gt; sigma) : (dataFile &gt;&gt; t &gt;&gt; e)) { ... }
  </code></pre>
  
  <p>but I don't sure if that trick is correct... Could you advise me some optimizations? Thank you!</p>
  
  <p><strong>EDIT</strong>
  Here is the full code snippet</p>
  
  <pre><code>if (minimizator_weighted) {
      while (dataFile &gt;&gt; t &gt;&gt; e &gt;&gt; sigma) { // read data file value by value
          data_set::pt point;
          point.t = t;
          point.e = e;
          point.c_vis = 0.0;
          point.c_invis = 0.0;
  
          if (std::abs(sigma) &lt;= GSL_SQRT_DBL_MIN) // check for division-by-zero error
              sigma = 1.0;
  
          point.sigma = sigma;
  
          set.curve.push_back(point); // store point
  
          data_numPoints++; // collect some stats
          set.curveAvg += e;
      }   
  }   
  else {
      while (dataFile &gt;&gt; t &gt;&gt; e) { // all the same but will not read standard deviation
          data_set::pt point;
          point.t = t;
          point.e = e;
          point.c_vis = 0.0;
          point.c_invis = 0.0;
  
          set.curve.push_back(point);
  
          data_numPoints++;
          set.curveAvg += e;
      }   
  }
  </code></pre>