1 #ifndef precomputed_value_sort_H
2 #define precomputed_value_sort_H
20 template<
class T,
class Scalar>
22 typedef std::pair<T,Scalar> SortPair;
23 bool operator()(
const SortPair&
a,
const SortPair&
b) {
24 return a.second < b.second;
28 template <
class T,
class Scalar,
class BinaryPredicate>
30 ComparePair(
const BinaryPredicate& cmp) : cmp_(cmp) {}
31 typedef std::pair<T,Scalar> SortPair;
32 bool operator()(
const SortPair&
a,
const SortPair&
b) {
33 return cmp_(a.second, b.second);
40 template<
class RandomAccessIterator,
class Extractor>
42 RandomAccessIterator
end,
43 const Extractor& extr) {
45 typedef typename Extractor::result_type
Scalar;
46 typedef std::pair<RandomAccessIterator,Scalar> SortPair;
48 std::vector<SortPair> tmpvec;
49 tmpvec.reserve(end-begin);
52 for (RandomAccessIterator
i=begin;
i!=
end;
i++) {
53 tmpvec.push_back(SortPair(
i,extr(*
i)));
57 LessPair<RandomAccessIterator,Scalar>());
62 for (
unsigned int i=0;
i<tmpvec.size();
i++) {
63 *(begin+
i) = tmpcopy[tmpvec[
i].
first - begin];
70 template<
class RandomAccessIterator,
class Extractor,
class BinaryPredicate>
72 RandomAccessIterator
end,
73 const Extractor& extr,
74 const BinaryPredicate& pred) {
76 typedef typename Extractor::result_type
Scalar;
77 typedef std::pair<RandomAccessIterator,Scalar> SortPair;
79 std::vector<SortPair> tmpvec;
80 tmpvec.reserve(end-begin);
83 for (RandomAccessIterator
i=begin;
i!=
end;
i++) {
84 tmpvec.push_back(SortPair(
i,extr(*
i)));
88 ComparePair< RandomAccessIterator,Scalar,BinaryPredicate>(pred));
93 for (
unsigned int i=0;
i<tmpvec.size();
i++) {
94 *(begin+
i) = tmpcopy[tmpvec[
i].
first - begin];
Container::value_type value_type
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)