Stxxl  1.2.1
test_sort_all_parameters.h
1 /***************************************************************************
2  * algo/test_sort_all_parameters.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
7  * Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #include <limits>
15 #include <stxxl/types>
16 
17 
18 template <typename KEY, unsigned SIZE>
19 struct my_type
20 {
21  typedef KEY key_type;
22 
23  key_type _key;
24  char _data[SIZE - sizeof(key_type)];
25 
26  my_type() { }
27  my_type(key_type __key) : _key(__key) { }
28 
29 #ifdef KEY_COMPARE
30  key_type key() const
31  {
32  return _key;
33  }
34 #endif
35 
36  static my_type<KEY, SIZE> min_value()
37  {
38  return my_type<KEY, SIZE>(std::numeric_limits<key_type>::min());
39  }
40  static my_type<KEY, SIZE> max_value()
41  {
42  return my_type<KEY, SIZE>(std::numeric_limits<key_type>::max());
43  }
44 };
45 
46 template <typename KEY, unsigned SIZE>
47 std::ostream & operator << (std::ostream & o, const my_type<KEY, SIZE> obj)
48 {
49 #ifndef KEY_COMPARE
50  o << obj._key;
51 #else
52  o << obj.key();
53 #endif
54  return o;
55 }
56 
57 #ifndef KEY_COMPARE
58 
59 template <typename KEY, unsigned SIZE>
60 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
61 {
62  return a._key < b._key;
63 }
64 
65 template <typename KEY, unsigned SIZE>
66 bool operator == (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
67 {
68  return a._key == b._key;
69 }
70 
71 template <typename KEY, unsigned SIZE>
72 bool operator != (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
73 {
74  return a._key != b._key;
75 }
76 
77 template <typename T>
78 struct Cmp : public std::less<T>
79 {
80  bool operator () (const T & a, const T & b) const
81  {
82  return a._key < b._key;
83  }
84 
85  static T min_value()
86  {
87  return T::min_value();
88  }
89  static T max_value()
90  {
91  return T::max_value();
92  }
93 };
94 
95 #else
96 
97 template <typename KEY, unsigned SIZE>
98 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
99 {
100  return a.key() < b.key();
101 }
102 
103 #endif
104 
105 struct zero
106 {
107  unsigned operator () ()
108  {
109  return 0;
110  }
111 };