Vaucanson 1.4
military_order.hh
00001 // military_order.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2008, 2009 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef MILITARY_ORDER_HH
00018 #define MILITARY_ORDER_HH
00019 
00020         /* Military strict order predicate.
00021          * This predicate applies to any type which provides a length method.
00022          * If two elements have the same length they are compared with operator<,
00023          * otherwise, the shorter is the smaller.
00024          *
00025          * Known algorithms using this : enumerate return a list sorted w.r.t military order.
00026          */
00027 
00028 namespace vcsn{
00029 
00030         template<typename T>
00031         struct MilitaryOrder{
00032 
00033                 bool operator()(const T& x, const T& y) const {
00034                         if(x.length()==y.length()) return (x<y);
00035                         else
00036                                 return x.length()<y.length();
00037                 }
00038 
00039         };
00040 
00041 } // ! vcsn
00042 
00043 #endif // ! MILITARY_ORDER_HH