[Lemon-commits] [lemon_svn] alpar: r1438 - hugo/trunk/src/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:27 CET 2006


Author: alpar
Date: Tue Jan  4 18:05:20 2005
New Revision: 1438

Modified:
   hugo/trunk/src/lemon/maps.h

Log:
- Missing 'const' keywords added
- Stupid implementation of 'AbsMap' has been corrected.

Modified: hugo/trunk/src/lemon/maps.h
==============================================================================
--- hugo/trunk/src/lemon/maps.h	(original)
+++ hugo/trunk/src/lemon/maps.h	Tue Jan  4 18:05:20 2005
@@ -196,7 +196,7 @@
     ///\e
     ///
     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    Value operator[](Key k) {return m1[k]+m2[k];}
+    Value operator[](Key k) const {return m1[k]+m2[k];}
   };
   
   ///Returns an \ref AddMap class
@@ -233,7 +233,7 @@
     ///\e
     ///
     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    Value operator[](Key k) {return m1[k]-m2[k];}
+    Value operator[](Key k) const {return m1[k]-m2[k];}
   };
   
   ///Returns a \ref SubMap class
@@ -269,7 +269,7 @@
     ///\e
     ///
     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    Value operator[](Key k) {return m1[k]*m2[k];}
+    Value operator[](Key k) const {return m1[k]*m2[k];}
   };
   
   ///Returns a \ref MulMap class
@@ -303,7 +303,7 @@
     ///\e
     ///
     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    Value operator[](Key k) {return m1[k]/m2[k];}
+    Value operator[](Key k) const {return m1[k]/m2[k];}
   };
   
   ///Returns a \ref DivMap class
@@ -326,7 +326,7 @@
   ///\code
   ///  ComposeMap<M1,M2> cm(m1,m2);
   ///\endcode
-  ///<tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
+  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
   ///
   ///Its \c Key is inherited from \c M2 and its \c Value is from
   ///\c M1.
@@ -347,7 +347,7 @@
     ///\e
     ///
     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    Value operator[](Key k) {return m1[m2[k]];}
+    Value operator[](Key k) const {return m1[m2[k]];}
   };
   
   ///Returns a \ref ComposeMap class
@@ -381,7 +381,7 @@
     ///\e
     ///
     NegMap(const M &_m) : m(_m) {};
-    Value operator[](Key k) {return -m[k];}
+    Value operator[](Key k) const {return -m[k];}
   };
   
   ///Returns a \ref NegMap class
@@ -395,26 +395,28 @@
   }
 
 
-  //\todo We need a unified way to handle the situation below!
-  struct _UnConvertible {};
-  template<class A> inline A t_abs(A a) {return _UnConvertible();}
-
-  template<> inline int t_abs<>(int n) {return abs(n);}
-  template<> inline long int t_abs<>(long int n) {return labs(n);}
-  //\bug llabs() is overloaded
-  template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
-
-  template<> inline float t_abs<>(float n) {return fabsf(n);}
-  template<> inline double t_abs<>(double n) {return fabs(n);}
-  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
-
   ///Absolute value of a map
 
   ///This \ref concept::ReadMap "read only map" returns the absolute value
   ///of the
   ///value returned by the
-  ///given map. Its \c Key and \c Value will be inherited from \c M.
-  ///The function <tt>Value abs(Value)<tt> must be defined, of course.
+  ///given map. Its \c Key and \c Value will be inherited
+  ///from <tt>M</tt>. <tt>Value</tt>
+  ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
+  ///operator must be defined for it, of course.
+  ///
+  ///\bug We need a unified way to handle the situation below:
+  ///\code
+  ///  struct _UnConvertible {};
+  ///  template<class A> inline A t_abs(A a) {return _UnConvertible();}
+  ///  template<> inline int t_abs<>(int n) {return abs(n);}
+  ///  template<> inline long int t_abs<>(long int n) {return labs(n);}
+  ///  template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
+  ///  template<> inline float t_abs<>(float n) {return fabsf(n);}
+  ///  template<> inline double t_abs<>(double n) {return fabs(n);}
+  ///  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
+  ///\endcode
+  
 
   template<class M> 
   class AbsMap
@@ -429,7 +431,7 @@
     ///\e
     ///
     AbsMap(const M &_m) : m(_m) {};
-    Value operator[](Key k) {return t_abs(m[k]);}
+    Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
   };
   
   ///Returns a \ref AbsMap class



More information about the Lemon-commits mailing list