00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef MLN_TRAIT_OP_ORD_HH
00028 # define MLN_TRAIT_OP_ORD_HH
00029 
00033 
00034 # include <mln/trait/op/decl.hh>
00035 # include <mln/trait/solve.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   
00042   namespace internal {
00043     template <typename T> struct ord_less;
00044     template <typename T> struct ord_vec;
00045   }
00046   namespace util {
00047     template <typename T> bool ord_strict(const T& lhs, const T& rhs);
00048   }
00049 
00050 
00051   namespace trait
00052   {
00053 
00054     namespace op
00055     {
00056 
00057       template <typename T>
00058       struct ord : public solve_unary<ord, T>
00059       {
00060       };
00061 
00062     } 
00063 
00064 
00065     template <template <class> class Category, typename T>
00066     struct set_unary_< op::ord, Category, T >
00067     {
00068       typedef mln::internal::ord_less<T> ret;
00069     };
00070 
00071 
00072   } 
00073 
00074 
00075   namespace internal
00076   {
00077 
00078     template <typename T>
00079     struct ord_less
00080     {
00081       bool strict(const T& lhs, const T& rhs) const;
00082       bool weak(const T& lhs, const T& rhs) const;
00083     };
00084 
00085     template <typename T>
00086     struct ord_vec
00087     {
00088       bool strict(const T& lhs, const T& rhs) const;
00089       bool weak(const T& lhs, const T& rhs) const;
00090     };
00091 
00092 
00093 # ifndef MLN_INCLUDE_ONLY
00094 
00095     
00096 
00097     template <typename T>
00098     inline
00099     bool
00100     ord_less<T>::strict(const T& lhs, const T& rhs) const
00101     {
00102       return lhs < rhs;
00103     }
00104 
00105     template <typename T>
00106     inline
00107     bool
00108     ord_less<T>::weak(const T& lhs, const T& rhs) const
00109     {
00110       return lhs <= rhs;
00111     }
00112 
00113     
00114 
00115     template <typename T>
00116     inline
00117     bool
00118     ord_vec<T>::strict(const T& lhs, const T& rhs) const
00119     {
00120       for (unsigned i = 0; i < T::dim; ++i)
00121         {
00122           if (lhs[i] == rhs[i])
00123             continue;
00124           return mln::util::ord_strict(lhs[i], rhs[i]);
00125         }
00126       return false;
00127     }
00128 
00129     template <typename T>
00130     inline
00131     bool
00132     ord_vec<T>::weak(const T& lhs, const T& rhs) const
00133     {
00134       for (unsigned i = 0; i < T::dim; ++i)
00135         {
00136           if (lhs[i] == rhs[i])
00137             continue;
00138           return mln::util::ord_strict(lhs[i], rhs[i]);
00139         }
00140       return true;
00141     }
00142 
00143 # endif // ! MLN_INCLUDE_ONLY
00144 
00145   } 
00146 
00147 } 
00148 
00149 
00150 # include <mln/util/ord.hh>
00151 # include <mln/trait/solve.hh>
00152 
00153 
00154 #endif // ! MLN_TRAIT_OP_ORD_HH