title: Calculating moving average of a stream of values stored in a vector
body: <p>I have a vector of structures that stores a stream of values that arrive at different intervals. The structure consists of two elements , one for the value and the other records the time when the value arrived. </p>
  
  <pre><code>struct Data {
      Time timeOfArrival;
      Time value;
  }cd;
  </code></pre>
  
  <p>Lets say that in another thread I want to calculate the moving average of the values that arrived in the last 10 (say) seconds. So in one thread the vector is being populated and in another I want to calculate the moving average.</p>