Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
gather.hpp
Go to the documentation of this file.
1/*
2 Copyright 2008 Adobe Systems Incorporated
3 Distributed under the Boost Software License - Version 1.0 (see the accompanying file LICENSE
4 or a copy at https://stlab.github.io/adobe_source_libraries/licenses.html)
5*/
6
7/**************************************************************************************************/
8
13
14#ifndef ADOBE_ALGORITHM_GATHER_HPP
15#define ADOBE_ALGORITHM_GATHER_HPP
16
17#include <algorithm> // for std::table_partition
18#include <functional>
19
20#include <boost/range/begin.hpp> // for boost::begin(range)
21#include <boost/range/end.hpp> // for boost::end(range)
22
23
24/**************************************************************************************************/
63
64/**************************************************************************************************/
65
66namespace adobe {
67
68/**************************************************************************************************/
69
74
75template <typename Iter, // Iter models BidirectionalIterator
76 typename Pred>
77// Pred models UnaryPredicate
78std::pair<Iter, Iter> gather(Iter first, Iter last, Iter pivot, Pred pred) {
79 // The first call partitions everything up to (but not including) the pivot element,
80 // while the second call partitions the rest of the sequence.
81 return std::make_pair(
82 std::stable_partition(
83 first, pivot,
84 std::bind(std::logical_not<bool>(), std::bind(pred, std::placeholders::_1))),
85 std::stable_partition(pivot, last, std::bind(pred, std::placeholders::_1)));
86}
87
88/**************************************************************************************************/
89
94
95template <typename BidirectionalRange, //
96 typename Pred> // Pred models UnaryPredicate
97std::pair<typename boost::range_iterator<BidirectionalRange>::type,
98 typename boost::range_iterator<BidirectionalRange>::type>
99gather(BidirectionalRange& range, typename boost::range_iterator<BidirectionalRange>::type pivot,
100 Pred pred) {
101 return adobe::gather(boost::begin(range), boost::end(range), pivot, pred);
102}
103
104/**************************************************************************************************/
105
106} // namespace adobe
107
108/**************************************************************************************************/
109
110#endif
std::pair< Iter, Iter > gather(Iter first, Iter last, Iter pivot, Pred pred)
iterator-based gather implementation
Definition gather.hpp:78
void pivot(I &i)
Definition forest.hpp:44