Add new algorithm 'gather'

[SVN r82584]
This commit is contained in:
Marshall Clow
2013-01-22 00:44:53 +00:00
parent 771375973f
commit 4ca6b10441
7 changed files with 681 additions and 1 deletions

View File

@ -58,6 +58,7 @@ Thanks to all the people who have reviewed this library and made suggestions for
[section:Misc Other Algorithms]
[include clamp-hpp.qbk]
[include gather.qbk]
[include hex.qbk]
[endsect]

79
doc/gather.qbk Normal file
View File

@ -0,0 +1,79 @@
[/ File gather.qbk]
[section:gather gather]
[/license
Copyright (c) 2013 Marshall Clow
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]
The header file 'boost/algorithm/gather.hpp' contains two variants of a single algorithm, `gather`.
`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.
[heading Interface]
The function `gather` returns a `std::pair` of iterators that denote the elements that satisfy the predicate.
There are two versions; one takes two iterators, and the other takes a range.
``
namespace boost { namespace algorithm {
template <typename ForwardIterator, typename Pred>
std::pair<ForwardIterator,ForwardIterator>
gather ( ForwardIterator first, ForwardIterator last, ForwardIterator pivot, Pred pred );
template <typename ForwardRange, typename Pred>
std::pair<typename boost::range_iterator<ForwardRange>::type, typename boost::range_iterator<ForwardRange>::type>
gather ( ForwardRange &range, typename boost::range_iterator<ForwardRange>::type pivot, Pred pred );
}}
``
[heading Examples]
Given an sequence containing:
``
0 1 2 3 4 5 6 7 8 9
``
a call to gather ( arr, arr + 10, arr + 4, IsEven ) will result in:
``
1 3 0 2 4 6 8 5 7 9
|---|-----|
first | second
pivot
``
where `first` and `second` are the fields of the pair that is returned by the call.
[heading Iterator Requirements]
`gather` work on all iterators except input or output iterators.
[heading Storage Requirements]
`gather` uses stable_partition, which will attempt to allocate temporary memory, but will work in-situ if there is none available.
[heading Complexity]
If there is sufficient memory available, the run time is linear: `O(N)`
If there is not any memory available, then the run time is `O(N log N)`.
[heading Exception Safety]
[heading Notes]
[endsect]
[/ File gather.qbk
Copyright 2013 Marshall Clow
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
]