COIN-OR::LEMON - Graph Library

Changeset 1044:f97380557656 in lemon-0.x for src/lemon


Ignore:
Timestamp:
01/04/05 18:05:20 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1438
Message:
  • Missing 'const' keywords added
  • Stupid implementation of 'AbsMap?' has been corrected.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/maps.h

    r1041 r1044  
    197197    ///
    198198    AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    199     Value operator[](Key k) {return m1[k]+m2[k];}
     199    Value operator[](Key k) const {return m1[k]+m2[k];}
    200200  };
    201201 
     
    234234    ///
    235235    SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    236     Value operator[](Key k) {return m1[k]-m2[k];}
     236    Value operator[](Key k) const {return m1[k]-m2[k];}
    237237  };
    238238 
     
    270270    ///
    271271    MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    272     Value operator[](Key k) {return m1[k]*m2[k];}
     272    Value operator[](Key k) const {return m1[k]*m2[k];}
    273273  };
    274274 
     
    304304    ///
    305305    DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    306     Value operator[](Key k) {return m1[k]/m2[k];}
     306    Value operator[](Key k) const {return m1[k]/m2[k];}
    307307  };
    308308 
     
    327327  ///  ComposeMap<M1,M2> cm(m1,m2);
    328328  ///\endcode
    329   ///<tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
     329  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
    330330  ///
    331331  ///Its \c Key is inherited from \c M2 and its \c Value is from
     
    348348    ///
    349349    ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    350     Value operator[](Key k) {return m1[m2[k]];}
     350    Value operator[](Key k) const {return m1[m2[k]];}
    351351  };
    352352 
     
    382382    ///
    383383    NegMap(const M &_m) : m(_m) {};
    384     Value operator[](Key k) {return -m[k];}
     384    Value operator[](Key k) const {return -m[k];}
    385385  };
    386386 
     
    396396
    397397
    398   //\todo We need a unified way to handle the situation below!
    399   struct _UnConvertible {};
    400   template<class A> inline A t_abs(A a) {return _UnConvertible();}
    401 
    402   template<> inline int t_abs<>(int n) {return abs(n);}
    403   template<> inline long int t_abs<>(long int n) {return labs(n);}
    404   //\bug llabs() is overloaded
    405   template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
    406 
    407   template<> inline float t_abs<>(float n) {return fabsf(n);}
    408   template<> inline double t_abs<>(double n) {return fabs(n);}
    409   template<> inline long double t_abs<>(long double n) {return fabsl(n);}
    410 
    411398  ///Absolute value of a map
    412399
     
    414401  ///of the
    415402  ///value returned by the
    416   ///given map. Its \c Key and \c Value will be inherited from \c M.
    417   ///The function <tt>Value abs(Value)<tt> must be defined, of course.
     403  ///given map. Its \c Key and \c Value will be inherited
     404  ///from <tt>M</tt>. <tt>Value</tt>
     405  ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
     406  ///operator must be defined for it, of course.
     407  ///
     408  ///\bug We need a unified way to handle the situation below:
     409  ///\code
     410  ///  struct _UnConvertible {};
     411  ///  template<class A> inline A t_abs(A a) {return _UnConvertible();}
     412  ///  template<> inline int t_abs<>(int n) {return abs(n);}
     413  ///  template<> inline long int t_abs<>(long int n) {return labs(n);}
     414  ///  template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
     415  ///  template<> inline float t_abs<>(float n) {return fabsf(n);}
     416  ///  template<> inline double t_abs<>(double n) {return fabs(n);}
     417  ///  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
     418  ///\endcode
     419 
    418420
    419421  template<class M>
     
    430432    ///
    431433    AbsMap(const M &_m) : m(_m) {};
    432     Value operator[](Key k) {return t_abs(m[k]);}
     434    Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
    433435  };
    434436 
Note: See TracChangeset for help on using the changeset viewer.