mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-06 09:16:33 +02:00
Gather does not (in general) work with forward iterators, even though it does on some systems
[SVN r83158]
This commit is contained in:
@ -22,13 +22,13 @@ There are two versions; one takes two iterators, and the other takes a range.
|
|||||||
``
|
``
|
||||||
namespace boost { namespace algorithm {
|
namespace boost { namespace algorithm {
|
||||||
|
|
||||||
template <typename ForwardIterator, typename Pred>
|
template <typename BidirectionalIterator, typename Pred>
|
||||||
std::pair<ForwardIterator,ForwardIterator>
|
std::pair<BidirectionalIterator,BidirectionalIterator>
|
||||||
gather ( ForwardIterator first, ForwardIterator last, ForwardIterator pivot, Pred pred );
|
gather ( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred );
|
||||||
|
|
||||||
template <typename ForwardRange, typename Pred>
|
template <typename BidirectionalRange, typename Pred>
|
||||||
std::pair<typename boost::range_iterator<ForwardRange>::type, typename boost::range_iterator<ForwardRange>::type>
|
std::pair<typename boost::range_iterator<const BidirectionalRange>::type, typename boost::range_iterator<const BidirectionalRange>::type>
|
||||||
gather ( ForwardRange &range, typename boost::range_iterator<ForwardRange>::type pivot, Pred pred );
|
gather ( const BidirectionalRange &range, typename boost::range_iterator<const BidirectionalRange>::type pivot, Pred pred );
|
||||||
|
|
||||||
}}
|
}}
|
||||||
``
|
``
|
||||||
@ -53,11 +53,11 @@ where `first` and `second` are the fields of the pair that is returned by the ca
|
|||||||
|
|
||||||
[heading Iterator Requirements]
|
[heading Iterator Requirements]
|
||||||
|
|
||||||
`gather` work on all iterators except input or output iterators.
|
`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.
|
||||||
|
|
||||||
[heading Storage Requirements]
|
[heading Storage Requirements]
|
||||||
|
|
||||||
`gather` uses stable_partition, which will attempt to allocate temporary memory, but will work in-situ if there is none available.
|
`gather` uses `stable_partition`, which will attempt to allocate temporary memory, but will work in-situ if there is none available.
|
||||||
|
|
||||||
[heading Complexity]
|
[heading Complexity]
|
||||||
|
|
||||||
|
@ -80,9 +80,10 @@ namespace boost { namespace algorithm {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename ForwardIterator, // Iter models ForwardIterator
|
typename BidirectionalIterator, // Iter models BidirectionalIterator
|
||||||
typename Pred> // Pred models UnaryPredicate
|
typename Pred> // Pred models UnaryPredicate
|
||||||
std::pair<ForwardIterator,ForwardIterator> gather ( ForwardIterator first, ForwardIterator last, ForwardIterator pivot, Pred pred )
|
std::pair<BidirectionalIterator, BidirectionalIterator> gather
|
||||||
|
( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred )
|
||||||
{
|
{
|
||||||
// The first call partitions everything up to (but not including) the pivot element,
|
// The first call partitions everything up to (but not including) the pivot element,
|
||||||
// while the second call partitions the rest of the sequence.
|
// while the second call partitions the rest of the sequence.
|
||||||
@ -99,14 +100,14 @@ std::pair<ForwardIterator,ForwardIterator> gather ( ForwardIterator first, Forwa
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename ForwardRange, //
|
typename BidirectionalRange, //
|
||||||
typename Pred> // Pred models UnaryPredicate
|
typename Pred> // Pred models UnaryPredicate
|
||||||
std::pair<
|
std::pair<
|
||||||
typename boost::range_iterator<ForwardRange>::type,
|
typename boost::range_iterator<const BidirectionalRange>::type,
|
||||||
typename boost::range_iterator<ForwardRange>::type>
|
typename boost::range_iterator<const BidirectionalRange>::type>
|
||||||
gather (
|
gather (
|
||||||
ForwardRange &range,
|
const BidirectionalRange &range,
|
||||||
typename boost::range_iterator<ForwardRange>::type pivot,
|
typename boost::range_iterator<const BidirectionalRange>::type pivot,
|
||||||
Pred pred )
|
Pred pred )
|
||||||
{
|
{
|
||||||
return boost::algorithm::gather ( boost::begin ( range ), boost::end ( range ), pivot, pred );
|
return boost::algorithm::gather ( boost::begin ( range ), boost::end ( range ), pivot, pred );
|
||||||
|
@ -55,14 +55,12 @@ void test_iterators ( Iterator first, Iterator last, Predicate comp, std::size_t
|
|||||||
template <typename Container, typename Predicate>
|
template <typename Container, typename Predicate>
|
||||||
void test_iterator_types ( const Container &c, Predicate comp, std::size_t offset ) {
|
void test_iterator_types ( const Container &c, Predicate comp, std::size_t offset ) {
|
||||||
typedef std::vector<typename Container::value_type> vec;
|
typedef std::vector<typename Container::value_type> vec;
|
||||||
typedef forward_iterator<typename vec::iterator> FI;
|
|
||||||
typedef bidirectional_iterator<typename vec::iterator> BDI;
|
typedef bidirectional_iterator<typename vec::iterator> BDI;
|
||||||
typedef random_access_iterator<typename vec::iterator> RAI;
|
typedef random_access_iterator<typename vec::iterator> RAI;
|
||||||
|
|
||||||
vec v;
|
vec v;
|
||||||
v.assign ( c.begin (), c.end ());
|
v.assign ( c.begin (), c.end ());
|
||||||
test_iterators ( FI ( v.begin ()), FI ( v.end ()), comp, offset );
|
|
||||||
v.assign ( c.begin (), c.end ());
|
|
||||||
test_iterators ( BDI ( v.begin ()), BDI ( v.end ()), comp, offset );
|
test_iterators ( BDI ( v.begin ()), BDI ( v.end ()), comp, offset );
|
||||||
v.assign ( c.begin (), c.end ());
|
v.assign ( c.begin (), c.end ());
|
||||||
test_iterators ( RAI ( v.begin ()), RAI ( v.end ()), comp, offset );
|
test_iterators ( RAI ( v.begin ()), RAI ( v.end ()), comp, offset );
|
||||||
|
Reference in New Issue
Block a user