title: Best way to return QVector
body: <p>Im trying to return a QVector from a function which is supposed to calculate the moving average. My question is how to make the function more efficient. The math is fine, Im more wondering if I do something wrong in returning the QVector. Here is the Code I have so far:</p>
  
  <pre><code>QVector&lt;double&gt; moving_exponential_average(const QVector&lt;double&gt;&amp; a, double lambda) {
          if(lambda &lt;0 ) {
              lambda = 0;
          }
          if(lambda &gt;1) {
              lambda = 1;
          }
          QVector&lt;double&gt; b;
          b.reserve(a.size());
  
          b.append(a[0]);
          double l_inv = 1-lambda;
          for(unsigned int i = 1; i &lt; a.size(); ++i) {
              b.append(a[i]*lambda+l_inv*b[i-1]);
          }
          return b;
      }
  </code></pre>
  
  <p>I use the default constructor to keep the QVector from setting a default value.
  I tried the same thing with resize which is much slower.
  Do you have any suggestions how this can be optimized?</p>
  
  <p>Regards</p>