00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes__std___pair_comparator_hh___included 00029 #define lestes__std___pair_comparator_hh___included 00030 00031 #include <lestes/common.hh> 00032 #include <functional> 00033 00034 /*! \file 00035 \brief lexicographic ordering on pairs 00036 \author TMA 00037 00038 This file provvides one template class ::lestes::std::pair_comparator, which 00039 performs lexicographic ordering. 00040 */ 00041 00042 package(lestes); 00043 package(std); 00044 00045 #ifdef _MSC_VER 00046 #define NO_TEMPLATE_TEMPLATE_PARAMETERS 1 00047 #else 00048 #define NO_TEMPLATE_TEMPLATE_PARAMETERS 0 00049 #endif 00050 00051 #if NO_TEMPLATE_TEMPLATE_PARAMETERS 00052 template < typename T > 00053 #else 00054 template < typename T, template < typename U > class ComparatorFirst = ::std::less, template < typename U > class ComparatorSecond = ComparatorFirst > 00055 #endif 00056 class pair_comparator { 00057 public: 00058 00059 #if NO_TEMPLATE_TEMPLATE_PARAMETERS 00060 typedef ::std::less < typename T::pointee_type::first_type > comparator_first; 00061 typedef ::std::less < typename T::pointee_type::second_type > comparator_second; 00062 #else 00063 typedef ComparatorFirst < typename T::pointee_type::first_type > comparator_first; 00064 typedef ComparatorSecond < typename T::pointee_type::second_type > comparator_second; 00065 #endif 00066 00067 /*! 00068 * \brief compares lexicographically a pair 00069 * 00070 * The inner workings determine the ordering by examining first the 00071 * first part of the pair. If the first pair's first element is 00072 * strictly less (where less is the relation of \p ComparatorFirst) 00073 * than the second's, the whole first pair is less (the relation 00074 * imposed by this comparator) than the second. If however the second's 00075 * first is less than the first's, the first pair is not less than 00076 * second. In the remaining case, i.e. neither first's first nor 00077 * second's first is less than the other, the relation on the pair is 00078 * determined solely by \p ComparatorSecond on the seconds of both 00079 * pairs. 00080 */ 00081 bool operator() (const T & a, const T & b) const 00082 { 00083 comparator_first ftc; 00084 bool ab = ftc(a->first, b->first); 00085 if (ab) 00086 return true; 00087 bool ba = ftc(b->first, a->first); 00088 if (ba) 00089 return false; 00090 comparator_second stc; 00091 return stc(a->second, b->second); 00092 } 00093 }; 00094 00095 end_package(std); 00096 end_package(lestes); 00097 00098 #endif // lestes__std___pair_comparator_hh___included 00099 /* vim: set ft=lestes : */
1.5.1-20070107