1 #ifndef precomputed_value_sort_H
2 #define precomputed_value_sort_H
18 template<
class T,
class Scalar>
20 typedef std::pair<T,Scalar> SortPair;
21 bool operator()(
const SortPair&
a,
const SortPair&
b) {
22 return a.second < b.second;
26 template <
class T,
class Scalar,
class BinaryPredicate>
28 ComparePair(
const BinaryPredicate& cmp) : cmp_(cmp) {}
29 typedef std::pair<T,Scalar> SortPair;
30 bool operator()(
const SortPair&
a,
const SortPair&
b) {
31 return cmp_(a.second, b.second);
38 template<
class RandomAccessIterator,
class Extractor>
40 RandomAccessIterator
end,
41 const Extractor& extr) {
43 typedef typename Extractor::result_type
Scalar;
44 typedef std::pair<RandomAccessIterator,Scalar> SortPair;
46 std::vector<SortPair> tmpvec;
47 tmpvec.reserve(end-begin);
50 for (RandomAccessIterator
i=begin;
i!=
end;
i++) {
51 tmpvec.push_back(SortPair(
i,extr(*
i)));
55 LessPair<RandomAccessIterator,Scalar>());
60 for (
unsigned int i=0;
i<tmpvec.size();
i++) {
61 *(begin+
i) = tmpcopy[tmpvec[
i].
first - begin];
68 template<
class RandomAccessIterator,
class Extractor,
class BinaryPredicate>
70 RandomAccessIterator
end,
71 const Extractor& extr,
72 const BinaryPredicate& pred) {
74 typedef typename Extractor::result_type
Scalar;
75 typedef std::pair<RandomAccessIterator,Scalar> SortPair;
77 std::vector<SortPair> tmpvec;
78 tmpvec.reserve(end-begin);
81 for (RandomAccessIterator
i=begin;
i!=
end;
i++) {
82 tmpvec.push_back(SortPair(
i,extr(*
i)));
86 ComparePair< RandomAccessIterator,Scalar,BinaryPredicate>(pred));
91 for (
unsigned int i=0;
i<tmpvec.size();
i++) {
92 *(begin+
i) = tmpcopy[tmpvec[
i].
first - begin];
Container::value_type value_type
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)