Hi Eric,
Thanks very much for your response. That does help, and I have some follow-ups.
First, let me make sure I am understanding correctly. If my Sample is
some FancyType whose default constructor does not do the right thing
(or perhaps does not exist), I should do:
accumulator_set
On 5/1/2013 1:13 PM, Gabriel Redner wrote:
Hi folks,
I am trying to implement a weighted accumulator, but I'm having trouble understanding a few things about the existing ones.
Looking at the implementation of weighted_sum, I see (weighted_sum.hpp:37):
template<typename Args> weighted_sum_impl(Args const &args) : weighted_sum_( args[parameter::keyword<Tag>::get() | Sample()] * numeric::one<Weight>::value ) { }
My questions are:
- It's taking the first sample from the args and multiplying it by a weight of 1. Isn't this wrong - ignoring the real weight of this sample? Shouldn't this produce incorrect results?
It's not taking the first sample. It's (optionally) taking an element representing zero. In most cases, a default-constructed Sample() is satisfactory for a zero element, but in some cases it's not. Consider what happens if your Sample type is std::vector<int>, and all your samples are going to be 3-element vectors. Then your zero is a std::vector<int> with 3 zeros. Any other starting value would cause all future computation to fail.
And we multiply by one to make the type promotion come out right.
- I've never understood anyways how there can be an initial argument during construction of the accumulator. I haven't found any explanation in the docs beyond "Maybe there is an initial value in the argument pack". Maybe? How?
I hope that clears it up.
-- Eric Niebler Boost.org http://www.boost.org
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost