Boost logo

Boost :

Subject: Re: [boost] [EXTERNAL] New algorithm in Boost.Algorithm: "gather" -- looking for comments
From: Belcourt, Kenneth (kbelco_at_[hidden])
Date: 2013-01-23 00:12:13


Hi Marshall,

On Jan 21, 2013, at 5:49 PM, Marshall Clow wrote:

> I have committed a new algorithm named "gather" into Boost.Algorithm.

Are scatter and assemble algorithms also forthcoming?

> gather() takes a collection of elements defined by a pair of iterators and moves the ones satisfying a predicate to them to a position (called the pivot) within the sequence. The algorithm is stable. The result is a pair of iterators that contains the items that satisfy the predicate.

This is a good start, but I'd like to see gather generalized. One change is to lift the requirement for the pivot being internal to the element sequence as in many computational engineering applications we don't want to destroy the source elements when we perform the gather, we want to gather (some parts of) the elements into another buffer. In this mode, pivot becomes less apt as you're no longer pivoting in the source sequence. We'd also want to allow a different iterator type for the output buffer so perhaps something like:

> template <typename ForwardIterator, typename OutputIterator, typename Pred>
> std::pair<ForwardIterator,ForwardIterator>
> gather ( ForwardIterator first, ForwardIterator last, OutputIterator result, Pred pred );

Also, could we just return the range end iterator instead of the pair since the user already told you where the range started? Something like:

> template <typename ForwardIterator, typename OutputIterator, typename Pred>
> OutputIterator gather(ForwardIterator first, ForwardIterator last, OutputIterator result, Pred pred);

I think this would still support your use case and might be a base we could build some engineering tools on, what do you think?

-- Noel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk