[accumulators] why not operator+=?

Neal Becker wrote:
A nit perhaps, but why not overload += to process samples?
Would that be horribly misleading if the accumulator set isn't actually doing addition? I'm happy with the function-style interface. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
Neal Becker wrote:
A nit perhaps, but why not overload += to process samples?
Would that be horribly misleading if the accumulator set isn't actually doing addition? I'm happy with the function-style interface.
Not sure what you mean by addition. Here, we are 'adding' a new sample (or samples) to the collection of samples. It doesn't matter whether the underlying accumulator then uses 'addition' or not. Seems clear to me.

Neal Becker escreveu:
Not sure what you mean by addition. Here, we are 'adding' a new sample (or samples) to the collection of samples. It doesn't matter whether the underlying accumulator then uses 'addition' or not. Seems clear to me.
Why not use operator<< like std::ostream uses? It implies something getting into something else, just the case here (IMHO). []s, rod

Eric Niebler wrote:
Neal Becker wrote:
A nit perhaps, but why not overload += to process samples?
Would that be horribly misleading if the accumulator set isn't actually doing addition? I'm happy with the function-style interface.
Just personal preference, but I also prefer the function style interface. A += interface would imply addition to me, whether it is what is really happening or not. John

John Phillips wrote:
Eric Niebler wrote:
Neal Becker wrote:
A nit perhaps, but why not overload += to process samples?
Would that be horribly misleading if the accumulator set isn't actually doing addition? I'm happy with the function-style interface.
Just personal preference, but I also prefer the function style interface. A += interface would imply addition to me, whether it is what is really happening or not.
John
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost Doesn't a += interface make an accumulate interface like:
std::accumulate(data.begin(), data.end(), acc); more appealing than : std::for_each(data.begin(), data.end(), acc); Alan

AMDG Alan Patterson wrote:
Doesn't a += interface make an accumulate interface like:
std::accumulate(data.begin(), data.end(), acc);
more appealing than :
std::for_each(data.begin(), data.end(), acc);
std::accumulate uses result = result + *iter; not result += *iter; In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Alan Patterson wrote:
Doesn't a += interface make an accumulate interface like:
std::accumulate(data.begin(), data.end(), acc);
more appealing than :
std::for_each(data.begin(), data.end(), acc);
std::accumulate uses result = result + *iter; not result += *iter;
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost Yes. But I guess the original question was that why not a += (or +) operator implemented in accumulator_set to add samples instead of operator().
Using std::accumulate to accumulate samples (in an accumulation library) seems more natural to me than the functional implementation. And, using accumulate implies addition operators. Alan

Alan Patterson wrote:
Steven Watanabe wrote:
AMDG
Alan Patterson wrote:
Doesn't a += interface make an accumulate interface like:
std::accumulate(data.begin(), data.end(), acc);
more appealing than :
std::for_each(data.begin(), data.end(), acc);
std::accumulate uses result = result + *iter; not result += *iter;
Yes. But I guess the original question was that why not a += (or +) operator implemented in accumulator_set to add samples instead of operator().
The answer to the original question is "because operator+ implies addition".
Using std::accumulate to accumulate samples (in an accumulation library) seems more natural to me than the functional implementation. And, using accumulate implies addition operators.
I respectfully disagree, and "using accumulate implies addition" is one reason. The other is that std::accumulate's interface gives it a very limited usage. std::accumulate accepts a sequence, an initial state and a binary operation. It applies that binary operation on each element and the current state to create a new state. In contrast, an accumulator_set maintains some very complicated and *hidden* internal state. Samples are added one at a time, and the way the internal state is modified cannot be expressed simply or efficiently as a binary operation that accepts the old state and the current sample. Conceptually, an accumulator_set is like std::accumulate's binary function with its state argument bound to it, making it a unary function -- unusable with std::accumulate. Trying to shoe-horn it back into the std::accumulate interface with a too-clever operator overload is simply misguided. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (6)
-
Alan Patterson
-
Eric Niebler
-
John Phillips
-
Neal Becker
-
Rodolfo Lima
-
Steven Watanabe