Last active
January 8, 2017 16:18
-
-
Save deque-blog/9bae5766d18ccba90a9015543b95b340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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