# HG changeset patch # User alpar # Date 1104858320 0 # Node ID f97380557656bf702c4374f61bb06462a31afb3c # Parent 52a2201a88e9979ea109bdde30fe5c9c9fe7f832 - Missing 'const' keywords added - Stupid implementation of 'AbsMap' has been corrected. diff -r 52a2201a88e9 -r f97380557656 src/lemon/maps.h --- a/src/lemon/maps.h Mon Jan 03 16:23:47 2005 +0000 +++ b/src/lemon/maps.h Tue Jan 04 17:05:20 2005 +0000 @@ -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 cm(m1,m2); ///\endcode - ///cm[x] will be equal to m1[m2[x]] + /// cm[x] will be equal to m1[m2[x]] /// ///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 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 Value abs(Value) must be defined, of course. + ///given map. Its \c Key and \c Value will be inherited + ///from M. Value + ///must be comparable to 0 and the unary - + ///operator must be defined for it, of course. + /// + ///\bug We need a unified way to handle the situation below: + ///\code + /// struct _UnConvertible {}; + /// template 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 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