Boost Users :
Subject: Re: [Boost-users] Overloading boost::for_each()
From: Eric Niebler (eric_at_[hidden])
Date: 2010-08-29 16:22:16
On 8/29/2010 2:27 PM, Jeremiah Willcock wrote:
> On Sun, 29 Aug 2010, Eric Niebler wrote:
>> On 8/29/2010 1:03 PM, Jeremiah Willcock wrote:
>>> I think just overloading for_each() and writing algorithms in terms of
>>> that when possible would get the same benefits, though.
>> This way lies madness. The separation of containers and algorithms in
>> the STL is what keeps it manageable. You don't want to implement N
>> algorithms over M container types. You want to define a concept on which
>> you can "overload" for_each.
> Yes, that's what I meant. Have a default implementation, but
> specifically allow it to be overloaded, then make other algorithms use
> for_each() so that they can use overloaded versions. Maybe the base
> algorithm should be some kind of fold like it is in a functional
> language, though.
No. There is no one-algorithm-to-rule-them-all, with which all other
algorithms can be implemented. There are different algorithms and
different sequence types. The trick is matching the best algorithm
implementation with the specific capabilities supported by the sequence.
Hence the iterator categories. And segmented iterators are an extra
category for which the algorithms can be specialized.
But I'm pretty sure you know all this, so I feel a bit strange saying
it. Have I missed something?
-- 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