Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active January 8, 2017 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/9bae5766d18ccba90a9015543b95b340 to your computer and use it in GitHub Desktop.
Save deque-blog/9bae5766d18ccba90a9015543b95b340 to your computer and use it in GitHub Desktop.
struct RunningAverage
{
double m_value;
int m_count;
};
struct GetAverage
{
RunningAverage operator()() const { return RunningAverage{ 0.0, 0 }; }
RunningAverage operator()(RunningAverage const& avg, double value) const
{
return RunningAverage {
(avg.m_value * avg.m_count + value) / (avg.m_count + 1),
avg.m_count + 1 };
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment