Stxxl  1.3.2
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 <[email protected]>
7  * Copyright (C) 2008, 2009 Andreas Beckmann <[email protected]>
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 template <unsigned n>
18 struct bulk
19 {
20  char _data[n];
21 };
22 
23 template <>
24 struct bulk<0>
25 { };
26 
27 template <typename KEY, unsigned SIZE>
28 struct my_type
29 {
30  typedef KEY key_type;
31 
32  key_type _key;
33  bulk<SIZE - sizeof(key_type)> _data;
34 
35  my_type() { }
36  my_type(key_type __key) : _key(__key) { }
37 
38 #ifdef KEY_COMPARE
39  key_type key() const
40  {
41  return _key;
42  }
43 #endif
44 
45  static my_type<KEY, SIZE> min_value()
46  {
47  return my_type<KEY, SIZE>(std::numeric_limits<key_type>::min());
48  }
49  static my_type<KEY, SIZE> max_value()
50  {
51  return my_type<KEY, SIZE>(std::numeric_limits<key_type>::max());
52  }
53 };
54 
55 template <typename KEY, unsigned SIZE>
56 std::ostream & operator << (std::ostream & o, const my_type<KEY, SIZE> obj)
57 {
58 #ifndef KEY_COMPARE
59  o << obj._key;
60 #else
61  o << obj.key();
62 #endif
63  return o;
64 }
65 
66 #ifndef KEY_COMPARE
67 
68 template <typename KEY, unsigned SIZE>
69 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
70 {
71  return a._key < b._key;
72 }
73 
74 template <typename KEY, unsigned SIZE>
75 bool operator == (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
76 {
77  return a._key == b._key;
78 }
79 
80 template <typename KEY, unsigned SIZE>
81 bool operator != (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
82 {
83  return a._key != b._key;
84 }
85 
86 template <typename T>
87 struct Cmp : public std::less<T>
88 {
89  bool operator () (const T & a, const T & b) const
90  {
91  return a._key < b._key;
92  }
93 
94  static T min_value()
95  {
96  return T::min_value();
97  }
98  static T max_value()
99  {
100  return T::max_value();
101  }
102 };
103 
104 #else
105 
106 template <typename KEY, unsigned SIZE>
107 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
108 {
109  return a.key() < b.key();
110 }
111 
112 #endif
113 
114 struct zero
115 {
116  unsigned operator () ()
117  {
118  return 0;
119  }
120 };