3 [section:gather gather]
6 Copyright (c) 2013 Marshall Clow
8 Distributed under the Boost Software License, Version 1.0.
9 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 The header file 'boost/algorithm/gather.hpp' contains two variants of a single algorithm, `gather`.
14 `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.
18 The function `gather` returns a `std::pair` of iterators that denote the elements that satisfy the predicate.
20 There are two versions; one takes two iterators, and the other takes a range.
23 namespace boost { namespace algorithm {
25 template <typename BidirectionalIterator, typename Pred>
26 std::pair<BidirectionalIterator,BidirectionalIterator>
27 gather ( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred );
29 template <typename BidirectionalRange, typename Pred>
30 std::pair<typename boost::range_iterator<const BidirectionalRange>::type, typename boost::range_iterator<const BidirectionalRange>::type>
31 gather ( const BidirectionalRange &range, typename boost::range_iterator<const BidirectionalRange>::type pivot, Pred pred );
38 Given an sequence containing:
43 a call to gather ( arr, arr + 10, arr + 4, IsEven ) will result in:
51 where `first` and `second` are the fields of the pair that is returned by the call.
54 [heading Iterator Requirements]
56 `gather` work on bidirectional iterators or better. This requirement comes from the usage of `stable_partition`, which requires bidirectional iterators. Some standard libraries (libstdc++ and libc++, for example) have implementations of `stable_partition` that work with forward iterators. If that is the case, then `gather` will work with forward iterators as well.
58 [heading Storage Requirements]
60 `gather` uses `stable_partition`, which will attempt to allocate temporary memory, but will work in-situ if there is none available.
64 If there is sufficient memory available, the run time is linear: `O(N)`
66 If there is not any memory available, then the run time is `O(N log N)`.
68 [heading Exception Safety]
75 Copyright 2013 Marshall Clow
76 Distributed under the Boost Software License, Version 1.0.
77 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).