gather.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2008 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /**************************************************************************************************/ 00008 00014 #ifndef ADOBE_ALGORITHM_GATHER_HPP 00015 #define ADOBE_ALGORITHM_GATHER_HPP 00016 00017 #include <algorithm> // for std::table_partition 00018 00019 #include <boost/bind.hpp> // for boost::bind 00020 #include <boost/range/begin.hpp> // for boost::begin(range) 00021 #include <boost/range/end.hpp> // for boost::end(range) 00022 00023 00024 /**************************************************************************************************/ 00064 /**************************************************************************************************/ 00065 00066 namespace adobe { 00067 00068 /**************************************************************************************************/ 00069 00075 template < 00076 typename Iter, // Iter models BidirectionalIterator 00077 typename Pred> // Pred models UnaryPredicate 00078 std::pair<Iter,Iter> gather ( Iter first, Iter last, Iter pivot, Pred pred ) 00079 { 00080 // The first call partitions everything up to (but not including) the pivot element, 00081 // while the second call partitions the rest of the sequence. 00082 return std::make_pair ( 00083 std::stable_partition ( first, pivot, !boost::bind ( pred, _1 )), 00084 std::stable_partition ( pivot, last, boost::bind ( pred, _1 )) ); 00085 } 00086 00087 /**************************************************************************************************/ 00088 00094 template < 00095 typename BidirectionalRange, // 00096 typename Pred> // Pred models UnaryPredicate 00097 std::pair< 00098 typename boost::range_iterator<BidirectionalRange>::type, 00099 typename boost::range_iterator<BidirectionalRange>::type> 00100 gather ( 00101 BidirectionalRange &range, 00102 typename boost::range_iterator<BidirectionalRange>::type pivot, 00103 Pred pred ) 00104 { 00105 return adobe::gather ( boost::begin ( range ), pivot, boost::end ( range ), pred ); 00106 } 00107 00108 /**************************************************************************************************/ 00109 00110 } // namespace adobe 00111 00112 /**************************************************************************************************/ 00113 00114 #endif 00115 |