Vaucanson  1.4.1
military_order.hh
1 // military_order.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2008, 2009 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef MILITARY_ORDER_HH
18 #define MILITARY_ORDER_HH
19 
20  /* Military strict order predicate.
21  * This predicate applies to any type which provides a length method.
22  * If two elements have the same length they are compared with operator<,
23  * otherwise, the shorter is the smaller.
24  *
25  * Known algorithms using this : enumerate return a list sorted w.r.t military order.
26  */
27 
28 namespace vcsn{
29 
30  template<typename T>
31  struct MilitaryOrder{
32 
33  bool operator()(const T& x, const T& y) const {
34  if(x.length()==y.length()) return (x<y);
35  else
36  return x.length()<y.length();
37  }
38 
39  };
40 
41 } // ! vcsn
42 
43 #endif // ! MILITARY_ORDER_HH