stlab.adobe.com Adobe Systems Incorporated
gather.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /**************************************************************************************************/
8 
14 #ifndef ADOBE_ALGORITHM_GATHER_HPP
15 #define ADOBE_ALGORITHM_GATHER_HPP
16 
17 #include <algorithm> // for std::table_partition
18 
19 #include <boost/bind.hpp> // for boost::bind
20 #include <boost/range/begin.hpp> // for boost::begin(range)
21 #include <boost/range/end.hpp> // for boost::end(range)
22 
23 
24 /**************************************************************************************************/
64 /**************************************************************************************************/
65 
66 namespace adobe {
67 
68 /**************************************************************************************************/
69 
75 template <
76  typename Iter, // Iter models BidirectionalIterator
77  typename Pred> // Pred models UnaryPredicate
78 std::pair<Iter,Iter> gather ( Iter first, Iter last, Iter pivot, Pred pred )
79 {
80 // The first call partitions everything up to (but not including) the pivot element,
81 // while the second call partitions the rest of the sequence.
82  return std::make_pair (
83  std::stable_partition ( first, pivot, !boost::bind ( pred, _1 )),
84  std::stable_partition ( pivot, last, boost::bind ( pred, _1 )) );
85 }
86 
87 /**************************************************************************************************/
88 
94 template <
95  typename BidirectionalRange, //
96  typename Pred> // Pred models UnaryPredicate
97 std::pair<
98  typename boost::range_iterator<BidirectionalRange>::type,
99  typename boost::range_iterator<BidirectionalRange>::type>
101  BidirectionalRange &range,
102  typename boost::range_iterator<BidirectionalRange>::type pivot,
103  Pred pred )
104 {
105  return adobe::gather ( boost::begin ( range ), pivot, boost::end ( range ), pred );
106 }
107 
108 /**************************************************************************************************/
109 
110 } // namespace adobe
111 
112 /**************************************************************************************************/
113 
114 #endif
115 

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google