12.07.2015 Views

An Introduction to the Interval Template Library

An Introduction to the Interval Template Library

An Introduction to the Interval Template Library

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Copyright © Joachim Faulhaber 2009Slide Design by Chih-Hao Tsai http://www.chtsai.orgAggregating with interval_mapsComputing averages via implementing opera<strong>to</strong>r +=(partys_guest_average.cpp)class counted_sum{public:counted_sum():_sum(0),_count(0){}counted_sum(int sum):_sum(sum),_count(1){}Examplesint sum()const {return _sum;}int count()const{return _count;}double average()const{ return _count==0 ? 0.0 : _sum/static_cast(_count); }counted_sum& opera<strong>to</strong>r += (const counted_sum& right){ _sum += right.sum(); _count += right.count(); return *this; }private:int _sum;int _count;};bool opera<strong>to</strong>r == (const counted_sum& left, const counted_sum& right){ return left.sum()==right.sum() && left.count()==right.count(); }16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!