1 /* 2 * Copyright 2003, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #ifndef _KERNEL_UTILS_ORDERS_H 6 #define _KERNEL_UTILS_ORDERS_H 7 8 namespace KernelUtilsOrder { 9 10 // Ascending 11 /*! \brief A compare function object implying and ascending order. 12 13 The < operator must be defined on the template argument type. 14 */ 15 template<typename Value> 16 class Ascending { 17 public: 18 inline int operator()(const Value &a, const Value &b) const 19 { 20 if (a < b) 21 return -1; 22 else if (b < a) 23 return 1; 24 return 0; 25 } 26 }; 27 28 // Descending 29 /*! \brief A compare function object implying and descending order. 30 31 The < operator must be defined on the template argument type. 32 */ 33 template<typename Value> 34 class Descending { 35 public: 36 inline int operator()(const Value &a, const Value &b) const 37 { 38 if (a < b) 39 return -1; 40 else if (b < a) 41 return 1; 42 return 0; 43 } 44 }; 45 46 } // namespace KernelUtilsOrder 47 48 #endif // _KERNEL_UTILS_ORDERS_H 49