Boost logo

Boost Users :

Subject: Re: [Boost-users] accumulators doc typo?
From: Eric Niebler (eric_at_[hidden])
Date: 2011-07-06 13:32:49


On 7/6/2011 4:40 AM, Olaf Peter wrote:
> Hi,
>
> at
> http://www.boost.org/doc/libs/1_46_1/doc/html/accumulators/user_s_guide.html
> in the example of section 'Droppable Accumulators' one can read
>
> // This will display "6 2 3"
> std::cout << sum(acc) << ' '
> << count(acc) << ' '
> << mean(acc);
>
> The text below says 'Note that at the point at which mean is dropped,
> sum is 3, count is 2, and therefore mean is 1.5'. After calculating my
> result is also 1.5 - the comment in the example isn't correct, isn't it?
>
> Probably the typo is in the upcoming release 1.47 too.

No, the comment in the docs is correct. Sum continues to accumulate, but
count does not --it was only added to the set to satisfy a dependency
from mean, which was dropped. So you end up with sum=6, count=2, and mean=3.

Note that if you change the declaration of acc in that example to:

  accumulator_set< double,
                   features< tag::sum, tag::count,
                             droppable<tag::mean> > > acc;

... the answer you get becomes "6 3 2". That is, once you have
explicitly asked for the count statistic, it no longer gets dropped
along with mean.

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net