Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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