vbl_sort.h
Go to the documentation of this file.
1 // This is core/vbl/vbl_sort.h
2 #ifndef vbl_sort_h_
3 #define vbl_sort_h_
4 //:
5 // \file
6 // \brief Collection of common predicates for sorting
7 // \author Andrew W. Fitzgibbon, Oxford RRG
8 // \date 19 Nov 97
9 //
10 // \verbatim
11 // Modifications
12 // 971119 AWF Initial version.
13 // PDA (Manchester) 21/03/2001: Tidied up the documentation
14 // \endverbatim
15 
16 int vbl_sort_double_ascending(double const&, double const&);
17 int vbl_sort_double_descending(double const&, double const&);
18 
19 int vbl_sort_int_ascending(int const&, int const&);
20 int vbl_sort_int_descending(int const&, int const&);
21 
22 
23 //: Collection of common predicates for sorting
24 template <class T>
26 {
27  static int ascend(const void* a, const void* b) {
28  T const& ta = *((T const*)a);
29  T const& tb = *((T const*)b);
30  return tb > ta ? -1 : tb == ta ? 0 : 1;
31  }
32  static int descend(const void* a, const void* b) {
33  return - ascend(a,b);
34  }
35 };
36 
37 #define VBL_SORT_INSTANTIATE(T) \
38 template struct vbl_sort_helper<T >
39 
40 #endif // vbl_sort_h_
int vbl_sort_double_descending(double const &, double const &)
Predicate that will sort in descending order.
Definition: vbl_sort.cxx:23
Collection of common predicates for sorting.
Definition: vbl_sort.h:25
int vbl_sort_double_ascending(double const &, double const &)
Predicate that will sort doubles in ascending order.
Definition: vbl_sort.cxx:11
int vbl_sort_int_ascending(int const &, int const &)
Ascending integers.
Definition: vbl_sort.cxx:35
static int ascend(const void *a, const void *b)
Definition: vbl_sort.h:27
int vbl_sort_int_descending(int const &, int const &)
Descending integers.
Definition: vbl_sort.cxx:47
static int descend(const void *a, const void *b)
Definition: vbl_sort.h:32