- Missing 'const' keywords added
authoralpar
Tue, 04 Jan 2005 17:05:20 +0000
changeset 1044f97380557656
parent 1043 52a2201a88e9
child 1045 1bf336c63f25
- Missing 'const' keywords added
- Stupid implementation of 'AbsMap' has been corrected.
src/lemon/maps.h
     1.1 --- a/src/lemon/maps.h	Mon Jan 03 16:23:47 2005 +0000
     1.2 +++ b/src/lemon/maps.h	Tue Jan 04 17:05:20 2005 +0000
     1.3 @@ -196,7 +196,7 @@
     1.4      ///\e
     1.5      ///
     1.6      AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
     1.7 -    Value operator[](Key k) {return m1[k]+m2[k];}
     1.8 +    Value operator[](Key k) const {return m1[k]+m2[k];}
     1.9    };
    1.10    
    1.11    ///Returns an \ref AddMap class
    1.12 @@ -233,7 +233,7 @@
    1.13      ///\e
    1.14      ///
    1.15      SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    1.16 -    Value operator[](Key k) {return m1[k]-m2[k];}
    1.17 +    Value operator[](Key k) const {return m1[k]-m2[k];}
    1.18    };
    1.19    
    1.20    ///Returns a \ref SubMap class
    1.21 @@ -269,7 +269,7 @@
    1.22      ///\e
    1.23      ///
    1.24      MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    1.25 -    Value operator[](Key k) {return m1[k]*m2[k];}
    1.26 +    Value operator[](Key k) const {return m1[k]*m2[k];}
    1.27    };
    1.28    
    1.29    ///Returns a \ref MulMap class
    1.30 @@ -303,7 +303,7 @@
    1.31      ///\e
    1.32      ///
    1.33      DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    1.34 -    Value operator[](Key k) {return m1[k]/m2[k];}
    1.35 +    Value operator[](Key k) const {return m1[k]/m2[k];}
    1.36    };
    1.37    
    1.38    ///Returns a \ref DivMap class
    1.39 @@ -326,7 +326,7 @@
    1.40    ///\code
    1.41    ///  ComposeMap<M1,M2> cm(m1,m2);
    1.42    ///\endcode
    1.43 -  ///<tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
    1.44 +  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
    1.45    ///
    1.46    ///Its \c Key is inherited from \c M2 and its \c Value is from
    1.47    ///\c M1.
    1.48 @@ -347,7 +347,7 @@
    1.49      ///\e
    1.50      ///
    1.51      ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    1.52 -    Value operator[](Key k) {return m1[m2[k]];}
    1.53 +    Value operator[](Key k) const {return m1[m2[k]];}
    1.54    };
    1.55    
    1.56    ///Returns a \ref ComposeMap class
    1.57 @@ -381,7 +381,7 @@
    1.58      ///\e
    1.59      ///
    1.60      NegMap(const M &_m) : m(_m) {};
    1.61 -    Value operator[](Key k) {return -m[k];}
    1.62 +    Value operator[](Key k) const {return -m[k];}
    1.63    };
    1.64    
    1.65    ///Returns a \ref NegMap class
    1.66 @@ -395,26 +395,28 @@
    1.67    }
    1.68  
    1.69  
    1.70 -  //\todo We need a unified way to handle the situation below!
    1.71 -  struct _UnConvertible {};
    1.72 -  template<class A> inline A t_abs(A a) {return _UnConvertible();}
    1.73 -
    1.74 -  template<> inline int t_abs<>(int n) {return abs(n);}
    1.75 -  template<> inline long int t_abs<>(long int n) {return labs(n);}
    1.76 -  //\bug llabs() is overloaded
    1.77 -  template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
    1.78 -
    1.79 -  template<> inline float t_abs<>(float n) {return fabsf(n);}
    1.80 -  template<> inline double t_abs<>(double n) {return fabs(n);}
    1.81 -  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
    1.82 -
    1.83    ///Absolute value of a map
    1.84  
    1.85    ///This \ref concept::ReadMap "read only map" returns the absolute value
    1.86    ///of the
    1.87    ///value returned by the
    1.88 -  ///given map. Its \c Key and \c Value will be inherited from \c M.
    1.89 -  ///The function <tt>Value abs(Value)<tt> must be defined, of course.
    1.90 +  ///given map. Its \c Key and \c Value will be inherited
    1.91 +  ///from <tt>M</tt>. <tt>Value</tt>
    1.92 +  ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
    1.93 +  ///operator must be defined for it, of course.
    1.94 +  ///
    1.95 +  ///\bug We need a unified way to handle the situation below:
    1.96 +  ///\code
    1.97 +  ///  struct _UnConvertible {};
    1.98 +  ///  template<class A> inline A t_abs(A a) {return _UnConvertible();}
    1.99 +  ///  template<> inline int t_abs<>(int n) {return abs(n);}
   1.100 +  ///  template<> inline long int t_abs<>(long int n) {return labs(n);}
   1.101 +  ///  template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
   1.102 +  ///  template<> inline float t_abs<>(float n) {return fabsf(n);}
   1.103 +  ///  template<> inline double t_abs<>(double n) {return fabs(n);}
   1.104 +  ///  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
   1.105 +  ///\endcode
   1.106 +  
   1.107  
   1.108    template<class M> 
   1.109    class AbsMap
   1.110 @@ -429,7 +431,7 @@
   1.111      ///\e
   1.112      ///
   1.113      AbsMap(const M &_m) : m(_m) {};
   1.114 -    Value operator[](Key k) {return t_abs(m[k]);}
   1.115 +    Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
   1.116    };
   1.117    
   1.118    ///Returns a \ref AbsMap class