Redesign of the map adaptors.
authordeba
Thu, 08 Sep 2005 14:34:50 +0000
changeset 1675fa89ffb27a6d
parent 1674 648aa2f33dc8
child 1676 c3e416514759
Redesign of the map adaptors.
/smart reference handling only used by functions/

Better handling of the function objects and functions.

\\\todo May we use operators instead of the addMap, subMap...?
lemon/maps.h
test/map_test.h
test/maps_test.cc
     1.1 --- a/lemon/maps.h	Thu Sep 01 20:35:30 2005 +0000
     1.2 +++ b/lemon/maps.h	Thu Sep 08 14:34:50 2005 +0000
     1.3 @@ -39,10 +39,11 @@
     1.4  
     1.5    /// Base class of maps.
     1.6    /// It provides the necessary <tt>typedef</tt>s required by the map concept.
     1.7 -  template<typename K, typename T>
     1.8 -  class MapBase
     1.9 -  {
    1.10 +  template<typename K, typename T, typename _NeedCopy = False>
    1.11 +  class MapBase {
    1.12    public:
    1.13 +    /// \e
    1.14 +    typedef _NeedCopy NeedCopy;
    1.15      ///\e
    1.16      typedef K Key;
    1.17      ///\e
    1.18 @@ -54,13 +55,13 @@
    1.19    /// If you have to provide a map only for its type definitions,
    1.20    /// or if you have to provide a writable map, but
    1.21    /// data written to it will sent to <tt>/dev/null</tt>...
    1.22 -  template<typename K, typename T>
    1.23 -  class NullMap : public MapBase<K,T>
    1.24 -  {
    1.25 +  template<typename K, typename T, typename NC = False>
    1.26 +  class NullMap : public MapBase<K, T, NC> {
    1.27    public:
    1.28 +    typedef MapBase<K, T, NC> Parent;
    1.29 +    typedef typename Parent::Key Key;
    1.30 +    typedef typename Parent::Value Value;
    1.31      
    1.32 -    typedef True NeedCopy;
    1.33 -
    1.34      /// Gives back a default constructed element.
    1.35      T operator[](const K&) const { return T(); }
    1.36      /// Absorbs the value.
    1.37 @@ -68,8 +69,8 @@
    1.38    };
    1.39  
    1.40    template <typename K, typename V> 
    1.41 -  NullMap<K, V> nullMap() {
    1.42 -    return NullMap<K, V>();
    1.43 +  NullMap<K, V, True> nullMap() {
    1.44 +    return NullMap<K, V, True>();
    1.45    }
    1.46  
    1.47  
    1.48 @@ -78,13 +79,15 @@
    1.49    /// This is a readable map which assigns a specified value to each key.
    1.50    /// In other aspects it is equivalent to the \ref NullMap.
    1.51    /// \todo set could be used to set the value.
    1.52 -  template<typename K, typename T>
    1.53 -  class ConstMap : public MapBase<K,T>
    1.54 -  {
    1.55 +  template<typename K, typename T, typename NC = False>
    1.56 +  class ConstMap : public MapBase<K, T, NC> {
    1.57 +  private:
    1.58      T v;
    1.59    public:
    1.60  
    1.61 -    typedef True NeedCopy;
    1.62 +    typedef MapBase<K, T, NC> Parent;
    1.63 +    typedef typename Parent::Key Key;
    1.64 +    typedef typename Parent::Value Value;
    1.65  
    1.66      /// Default constructor
    1.67  
    1.68 @@ -102,37 +105,49 @@
    1.69  
    1.70      template<typename T1>
    1.71      struct rebind {
    1.72 -      typedef ConstMap<K,T1> other;
    1.73 +      typedef ConstMap<K, T1> other;
    1.74      };
    1.75  
    1.76      template<typename T1>
    1.77 -    ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
    1.78 +    ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
    1.79    };
    1.80  
    1.81    ///Returns a \ref ConstMap class
    1.82  
    1.83    ///This function just returns a \ref ConstMap class.
    1.84    ///\relates ConstMap
    1.85 -  template<class K,class V> 
    1.86 -  inline ConstMap<K,V> constMap(const V &v) 
    1.87 -  {
    1.88 -    return ConstMap<K,V>(v);
    1.89 +  template<typename K, typename V> 
    1.90 +  inline ConstMap<K, V, True> constMap(const V &v) {
    1.91 +    return ConstMap<K, V, True>(v);
    1.92    }
    1.93  
    1.94  
    1.95    //\todo to document later
    1.96    template<typename T, T v>
    1.97    struct Const { };
    1.98 +
    1.99    //\todo to document later
   1.100 -  template<typename K, typename V, V v>
   1.101 -  class ConstMap<K, Const<V, v> > : public MapBase<K, V>
   1.102 -  {
   1.103 +  template<typename K, typename V, V v, typename NC>
   1.104 +  class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
   1.105    public:
   1.106 +    typedef MapBase<K, V, False> Parent;
   1.107 +    typedef typename Parent::Key Key;
   1.108 +    typedef typename Parent::Value Value;
   1.109 +
   1.110      ConstMap() { }
   1.111      V operator[](const K&) const { return v; }
   1.112      void set(const K&, const V&) { }
   1.113    };
   1.114  
   1.115 +  ///Returns a \ref ConstMap class
   1.116 +
   1.117 +  ///This function just returns a \ref ConstMap class.
   1.118 +  ///\relates ConstMap
   1.119 +  template<typename K, typename V, V v> 
   1.120 +  inline ConstMap<K, Const<V, v>, True> constMap() {
   1.121 +    return ConstMap<K, Const<V, v>, True>();
   1.122 +  }
   1.123 +
   1.124    /// \c std::map wrapper
   1.125  
   1.126    /// This is essentially a wrapper for \c std::map. With addition that
   1.127 @@ -140,8 +155,8 @@
   1.128    ///
   1.129    /// \todo Provide allocator parameter...
   1.130    template <typename K, typename T, typename Compare = std::less<K> >
   1.131 -  class StdMap : public std::map<K,T,Compare> {
   1.132 -    typedef std::map<K,T,Compare> parent;
   1.133 +  class StdMap : public std::map<K, T, Compare> {
   1.134 +    typedef std::map<K, T, Compare> parent;
   1.135      T v;
   1.136      typedef typename parent::value_type PairType;
   1.137  
   1.138 @@ -171,13 +186,14 @@
   1.139      StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
   1.140      
   1.141      template<typename T1, typename Comp1>
   1.142 -    StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
   1.143 +    StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) { 
   1.144        //FIXME; 
   1.145      }
   1.146  
   1.147      Reference operator[](const Key &k) {
   1.148        return insert(PairType(k,v)).first -> second;
   1.149      }
   1.150 +
   1.151      ConstReference operator[](const Key &k) const {
   1.152        typename parent::iterator i = lower_bound(k);
   1.153        if (i == parent::end() || parent::key_comp()(k, (*i).first))
   1.154 @@ -197,7 +213,7 @@
   1.155  
   1.156      template<typename T1>
   1.157      struct rebind {
   1.158 -      typedef StdMap<Key,T1,Compare> other;
   1.159 +      typedef StdMap<Key, T1,Compare> other;
   1.160      };
   1.161    };
   1.162  
   1.163 @@ -210,33 +226,40 @@
   1.164    ///
   1.165    /// This mapping gives back the given key as value without any
   1.166    /// modification. 
   1.167 -  template <typename T>
   1.168 -  class IdentityMap {
   1.169 +  template <typename T, typename NC = False>
   1.170 +  class IdentityMap : public MapBase<T, T, NC> {
   1.171    public:
   1.172 -    typedef T Key;
   1.173 -    typedef T Value;
   1.174 +    typedef MapBase<T, T, NC> Parent;
   1.175 +    typedef typename Parent::Key Key;
   1.176 +    typedef typename Parent::Value Value;
   1.177  
   1.178 -    const Value& operator[](const Key& t) const {
   1.179 +    const T& operator[](const T& t) const {
   1.180        return t;
   1.181      }
   1.182    };
   1.183  
   1.184 +  ///Returns an \ref IdentityMap class
   1.185 +
   1.186 +  ///This function just returns an \ref IdentityMap class.
   1.187 +  ///\relates IdentityMap
   1.188 +  template<typename T>
   1.189 +  inline IdentityMap<T, True> identityMap() {
   1.190 +    return IdentityMap<T, True>();
   1.191 +  }
   1.192 +  
   1.193 +
   1.194    ///Convert the \c Value of a map to another type.
   1.195  
   1.196    ///This \ref concept::ReadMap "read only map"
   1.197    ///converts the \c Value of a maps to type \c T.
   1.198    ///Its \c Key is inherited from \c M.
   1.199 -  template<class M, class T> 
   1.200 -  class ConvertMap {
   1.201 +  template <typename M, typename T, typename NC = False> 
   1.202 +  class ConvertMap : public MapBase<typename M::Key, T, NC> {
   1.203      typename SmartConstReference<M>::Type m;
   1.204    public:
   1.205 -
   1.206 -    typedef True NeedCopy;
   1.207 -
   1.208 -    ///\e
   1.209 -    typedef typename M::Key Key;
   1.210 -    ///\e
   1.211 -    typedef T Value;
   1.212 +    typedef MapBase<typename M::Key, T, NC> Parent;
   1.213 +    typedef typename Parent::Key Key;
   1.214 +    typedef typename Parent::Value Value;
   1.215  
   1.216      ///Constructor
   1.217  
   1.218 @@ -249,7 +272,7 @@
   1.219      /// The subscript operator.
   1.220      /// \param k The key
   1.221      /// \return The target of the edge 
   1.222 -    Value operator[](Key k) const {return m[k];}
   1.223 +    Value operator[](const Key& k) const {return m[k];}
   1.224    };
   1.225    
   1.226    ///Returns an \ref ConvertMap class
   1.227 @@ -257,10 +280,9 @@
   1.228    ///This function just returns an \ref ConvertMap class.
   1.229    ///\relates ConvertMap
   1.230    ///\todo The order of the template parameters are changed.
   1.231 -  template<class T, class M>
   1.232 -  inline ConvertMap<M,T> convertMap(const M &m) 
   1.233 -  {
   1.234 -    return ConvertMap<M,T>(m);
   1.235 +  template<typename T, typename M>
   1.236 +  inline ConvertMap<M, T, True> convertMap(const M &m) {
   1.237 +    return ConvertMap<M, T, True>(m);
   1.238    }
   1.239  
   1.240    ///Sum of two maps
   1.241 @@ -269,20 +291,15 @@
   1.242    ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   1.243    ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   1.244  
   1.245 -  template<class M1,class M2> 
   1.246 -  class AddMap
   1.247 -  {
   1.248 +  template<typename M1, typename M2, typename NC = False> 
   1.249 +  class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   1.250      typename SmartConstReference<M1>::Type m1;
   1.251      typename SmartConstReference<M2>::Type m2;
   1.252  
   1.253    public:
   1.254 -
   1.255 -    typedef True NeedCopy;
   1.256 -
   1.257 -    ///\e
   1.258 -    typedef typename M1::Key Key;
   1.259 -    ///\e
   1.260 -    typedef typename M1::Value Value;
   1.261 +    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   1.262 +    typedef typename Parent::Key Key;
   1.263 +    typedef typename Parent::Value Value;
   1.264  
   1.265      ///Constructor
   1.266      AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.267 @@ -296,10 +313,9 @@
   1.268    ///
   1.269    ///\relates AddMap
   1.270    ///\todo Wrong scope in Doxygen when \c \\relates is used
   1.271 -  template<class M1,class M2> 
   1.272 -  inline AddMap<M1,M2> addMap(const M1 &m1,const M2 &m2) 
   1.273 -  {
   1.274 -    return AddMap<M1,M2>(m1,m2);
   1.275 +  template<typename M1, typename M2> 
   1.276 +  inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
   1.277 +    return AddMap<M1, M2, True>(m1,m2);
   1.278    }
   1.279  
   1.280    ///Shift a map with a constant.
   1.281 @@ -317,25 +333,21 @@
   1.282    ///  ConstMap<X::Key, X::Value> c_tmp(v);
   1.283    ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
   1.284    ///\endcode
   1.285 -  template<class M> 
   1.286 -  class ShiftMap
   1.287 -  {
   1.288 +  template<typename M, typename NC = False> 
   1.289 +  class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
   1.290      typename SmartConstReference<M>::Type m;
   1.291      typename M::Value v;
   1.292    public:
   1.293 -
   1.294 -    typedef True NeedCopy;
   1.295 -    ///\e
   1.296 -    typedef typename M::Key Key;
   1.297 -    ///\e
   1.298 -    typedef typename M::Value Value;
   1.299 +    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   1.300 +    typedef typename Parent::Key Key;
   1.301 +    typedef typename Parent::Value Value;
   1.302  
   1.303      ///Constructor
   1.304  
   1.305      ///Constructor
   1.306      ///\param _m is the undelying map
   1.307      ///\param _v is the shift value
   1.308 -    ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
   1.309 +    ShiftMap(const M &_m, const Value &_v ) : m(_m), v(_v) {};
   1.310      Value operator[](Key k) const {return m[k]+v;}
   1.311    };
   1.312    
   1.313 @@ -344,10 +356,9 @@
   1.314    ///This function just returns an \ref ShiftMap class.
   1.315    ///\relates ShiftMap
   1.316    ///\todo A better name is required.
   1.317 -  template<class M> 
   1.318 -  inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v) 
   1.319 -  {
   1.320 -    return ShiftMap<M>(m,v);
   1.321 +  template<typename M> 
   1.322 +  inline ShiftMap<M, True> shiftMap(const M &m,const typename M::Value &v) {
   1.323 +    return ShiftMap<M, True>(m,v);
   1.324    }
   1.325  
   1.326    ///Difference of two maps
   1.327 @@ -357,18 +368,14 @@
   1.328    ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   1.329    ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   1.330  
   1.331 -  template<class M1,class M2> 
   1.332 -  class SubMap
   1.333 -  {
   1.334 +  template<typename M1, typename M2, typename NC = False> 
   1.335 +  class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   1.336      typename SmartConstReference<M1>::Type m1;
   1.337      typename SmartConstReference<M2>::Type m2;
   1.338    public:
   1.339 -
   1.340 -    typedef True NeedCopy;
   1.341 -    ///\e
   1.342 -    typedef typename M1::Key Key;
   1.343 -    ///\e
   1.344 -    typedef typename M1::Value Value;
   1.345 +    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   1.346 +    typedef typename Parent::Key Key;
   1.347 +    typedef typename Parent::Value Value;
   1.348  
   1.349      ///Constructor
   1.350      SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.351 @@ -380,10 +387,9 @@
   1.352    ///This function just returns a \ref SubMap class.
   1.353    ///
   1.354    ///\relates SubMap
   1.355 -  template<class M1,class M2> 
   1.356 -  inline SubMap<M1,M2> subMap(const M1 &m1,const M2 &m2) 
   1.357 -  {
   1.358 -    return SubMap<M1,M2>(m1,m2);
   1.359 +  template<typename M1, typename M2> 
   1.360 +  inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
   1.361 +    return SubMap<M1, M2, True>(m1, m2);
   1.362    }
   1.363  
   1.364    ///Product of two maps
   1.365 @@ -394,18 +400,14 @@
   1.366    ///maps. Its \c Key and \c Value will be inherited from \c M1.
   1.367    ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   1.368  
   1.369 -  template<class M1,class M2> 
   1.370 -  class MulMap
   1.371 -  {
   1.372 +  template<typename M1, typename M2, typename NC = False> 
   1.373 +  class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   1.374      typename SmartConstReference<M1>::Type m1;
   1.375      typename SmartConstReference<M2>::Type m2;
   1.376    public:
   1.377 -
   1.378 -    typedef True NeedCopy;
   1.379 -    ///\e
   1.380 -    typedef typename M1::Key Key;
   1.381 -    ///\e
   1.382 -    typedef typename M1::Value Value;
   1.383 +    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   1.384 +    typedef typename Parent::Key Key;
   1.385 +    typedef typename Parent::Value Value;
   1.386  
   1.387      ///Constructor
   1.388      MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.389 @@ -416,10 +418,9 @@
   1.390  
   1.391    ///This function just returns a \ref MulMap class.
   1.392    ///\relates MulMap
   1.393 -  template<class M1,class M2> 
   1.394 -  inline MulMap<M1,M2> mulMap(const M1 &m1,const M2 &m2) 
   1.395 -  {
   1.396 -    return MulMap<M1,M2>(m1,m2);
   1.397 +  template<typename M1, typename M2> 
   1.398 +  inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
   1.399 +    return MulMap<M1, M2, True>(m1,m2);
   1.400    }
   1.401   
   1.402    ///Scales a maps with a constant.
   1.403 @@ -437,18 +438,14 @@
   1.404    ///  ConstMap<X::Key, X::Value> c_tmp(v);
   1.405    ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
   1.406    ///\endcode
   1.407 -  template<class M> 
   1.408 -  class ScaleMap
   1.409 -  {
   1.410 +  template<typename M, typename NC = False> 
   1.411 +  class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
   1.412      typename SmartConstReference<M>::Type m;
   1.413      typename M::Value v;
   1.414    public:
   1.415 -
   1.416 -    typedef True NeedCopy;
   1.417 -    ///\e
   1.418 -    typedef typename M::Key Key;
   1.419 -    ///\e
   1.420 -    typedef typename M::Value Value;
   1.421 +    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   1.422 +    typedef typename Parent::Key Key;
   1.423 +    typedef typename Parent::Value Value;
   1.424  
   1.425      ///Constructor
   1.426  
   1.427 @@ -464,10 +461,9 @@
   1.428    ///This function just returns an \ref ScaleMap class.
   1.429    ///\relates ScaleMap
   1.430    ///\todo A better name is required.
   1.431 -  template<class M> 
   1.432 -  inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v) 
   1.433 -  {
   1.434 -    return ScaleMap<M>(m,v);
   1.435 +  template<typename M> 
   1.436 +  inline ScaleMap<M, True> scaleMap(const M &m,const typename M::Value &v) {
   1.437 +    return ScaleMap<M, True>(m,v);
   1.438    }
   1.439  
   1.440    ///Quotient of two maps
   1.441 @@ -477,18 +473,14 @@
   1.442    ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   1.443    ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   1.444  
   1.445 -  template<class M1,class M2> 
   1.446 -  class DivMap
   1.447 -  {
   1.448 +  template<typename M1, typename M2, typename NC = False> 
   1.449 +  class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   1.450      typename SmartConstReference<M1>::Type m1;
   1.451      typename SmartConstReference<M2>::Type m2;
   1.452    public:
   1.453 -
   1.454 -    typedef True NeedCopy;
   1.455 -    ///\e
   1.456 -    typedef typename M1::Key Key;
   1.457 -    ///\e
   1.458 -    typedef typename M1::Value Value;
   1.459 +    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   1.460 +    typedef typename Parent::Key Key;
   1.461 +    typedef typename Parent::Value Value;
   1.462  
   1.463      ///Constructor
   1.464      DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.465 @@ -499,10 +491,9 @@
   1.466  
   1.467    ///This function just returns a \ref DivMap class.
   1.468    ///\relates DivMap
   1.469 -  template<class M1,class M2> 
   1.470 -  inline DivMap<M1,M2> divMap(const M1 &m1,const M2 &m2) 
   1.471 -  {
   1.472 -    return DivMap<M1,M2>(m1,m2);
   1.473 +  template<typename M1, typename M2> 
   1.474 +  inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
   1.475 +    return DivMap<M1, M2, True>(m1,m2);
   1.476    }
   1.477    
   1.478    ///Composition of two maps
   1.479 @@ -513,7 +504,7 @@
   1.480    ///of \c M2,
   1.481    ///then for
   1.482    ///\code
   1.483 -  ///  ComposeMap<M1,M2> cm(m1,m2);
   1.484 +  ///  ComposeMap<M1, M2> cm(m1,m2);
   1.485    ///\endcode
   1.486    /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
   1.487    ///
   1.488 @@ -522,18 +513,14 @@
   1.489    ///The \c M2::Value must be convertible to \c M1::Key.
   1.490    ///\todo Check the requirements.
   1.491  
   1.492 -  template<class M1,class M2> 
   1.493 -  class ComposeMap
   1.494 -  {
   1.495 +  template <typename M1, typename M2, typename NC = False> 
   1.496 +  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
   1.497      typename SmartConstReference<M1>::Type m1;
   1.498      typename SmartConstReference<M2>::Type m2;
   1.499    public:
   1.500 -
   1.501 -    typedef True NeedCopy;
   1.502 -    ///\e
   1.503 -    typedef typename M2::Key Key;
   1.504 -    ///\e
   1.505 -    typedef typename M1::Value Value;
   1.506 +    typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
   1.507 +    typedef typename Parent::Key Key;
   1.508 +    typedef typename Parent::Value Value;
   1.509  
   1.510      ///Constructor
   1.511      ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.512 @@ -544,10 +531,9 @@
   1.513    ///This function just returns a \ref ComposeMap class.
   1.514    ///
   1.515    ///\relates ComposeMap
   1.516 -  template<class M1,class M2> 
   1.517 -  inline ComposeMap<M1,M2> composeMap(const M1 &m1,const M2 &m2) 
   1.518 -  {
   1.519 -    return ComposeMap<M1,M2>(m1,m2);
   1.520 +  template <typename M1, typename M2> 
   1.521 +  inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
   1.522 +    return ComposeMap<M1, M2, True>(m1,m2);
   1.523    }
   1.524    
   1.525    ///Combines of two maps using an STL (binary) functor.
   1.526 @@ -563,7 +549,7 @@
   1.527    ///and \c f is of \c F,
   1.528    ///then for
   1.529    ///\code
   1.530 -  ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
   1.531 +  ///  CombineMap<M1, M2,F,V> cm(m1,m2,f);
   1.532    ///\endcode
   1.533    /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
   1.534    ///
   1.535 @@ -573,19 +559,17 @@
   1.536    ///to \c V.
   1.537    ///\todo Check the requirements.
   1.538  
   1.539 -  template<class M1,class M2,class F,class V = typename F::result_type> 
   1.540 -  class CombineMap
   1.541 -  {
   1.542 +  template<typename M1, typename M2, typename F,
   1.543 +	   typename V = typename F::result_type,
   1.544 +	   typename NC = False> 
   1.545 +  class CombineMap : public MapBase<typename M1::Key, V, NC> {
   1.546      typename SmartConstReference<M1>::Type m1;
   1.547      typename SmartConstReference<M2>::Type m2;
   1.548      F f;
   1.549    public:
   1.550 -
   1.551 -    typedef True NeedCopy;
   1.552 -    ///\e
   1.553 -    typedef typename M1::Key Key;
   1.554 -    ///\e
   1.555 -    typedef V Value;
   1.556 +    typedef MapBase<typename M1::Key, V, NC> Parent;
   1.557 +    typedef typename Parent::Key Key;
   1.558 +    typedef typename Parent::Value Value;
   1.559  
   1.560      ///Constructor
   1.561      CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   1.562 @@ -609,10 +593,22 @@
   1.563    ///\endcode
   1.564    ///
   1.565    ///\relates CombineMap
   1.566 -  template<class M1,class M2,class F> 
   1.567 -  inline CombineMap<M1,M2,F> combineMap(const M1 &m1,const M2 &m2,const F &f) 
   1.568 -  {
   1.569 -    return CombineMap<M1,M2,F>(m1,m2,f);
   1.570 +  template<typename M1, typename M2, typename F, typename V> 
   1.571 +  inline CombineMap<M1, M2, F, V, True> 
   1.572 +  combineMap(const M1& m1,const M2& m2, const F& f) {
   1.573 +    return CombineMap<M1, M2, F, V, True>(m1,m2,f);
   1.574 +  }
   1.575 +
   1.576 +  template<typename M1, typename M2, typename F> 
   1.577 +  inline CombineMap<M1, M2, F, typename F::result_type, True> 
   1.578 +  combineMap(const M1& m1, const M2& m2, const F& f) {
   1.579 +    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
   1.580 +  }
   1.581 +
   1.582 +  template<typename M1, typename M2, typename K1, typename K2, typename V> 
   1.583 +  inline CombineMap<M1, M2, V (*)(K1, K2), V, True> 
   1.584 +  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
   1.585 +    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   1.586    }
   1.587  
   1.588    ///Negative value of a map
   1.589 @@ -623,17 +619,13 @@
   1.590    ///given map. Its \c Key and \c Value will be inherited from \c M.
   1.591    ///The unary \c - operator must be defined for \c Value, of course.
   1.592  
   1.593 -  template<class M> 
   1.594 -  class NegMap
   1.595 -  {
   1.596 +  template<typename M, typename NC = False> 
   1.597 +  class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
   1.598      typename SmartConstReference<M>::Type m;
   1.599    public:
   1.600 -
   1.601 -    typedef True NeedCopy;
   1.602 -    ///\e
   1.603 -    typedef typename M::Key Key;
   1.604 -    ///\e
   1.605 -    typedef typename M::Value Value;
   1.606 +    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   1.607 +    typedef typename Parent::Key Key;
   1.608 +    typedef typename Parent::Value Value;
   1.609  
   1.610      ///Constructor
   1.611      NegMap(const M &_m) : m(_m) {};
   1.612 @@ -644,10 +636,9 @@
   1.613  
   1.614    ///This function just returns a \ref NegMap class.
   1.615    ///\relates NegMap
   1.616 -  template<class M> 
   1.617 -  inline NegMap<M> negMap(const M &m) 
   1.618 -  {
   1.619 -    return NegMap<M>(m);
   1.620 +  template <typename M> 
   1.621 +  inline NegMap<M, True> negMap(const M &m) {
   1.622 +    return NegMap<M, True>(m);
   1.623    }
   1.624  
   1.625  
   1.626 @@ -674,31 +665,30 @@
   1.627    ///\endcode
   1.628    
   1.629  
   1.630 -  template<class M> 
   1.631 -  class AbsMap
   1.632 -  {
   1.633 +  template<typename M, typename NC = False> 
   1.634 +  class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
   1.635      typename SmartConstReference<M>::Type m;
   1.636    public:
   1.637 -
   1.638 -    typedef True NeedCopy;
   1.639 -    ///\e
   1.640 -    typedef typename M::Key Key;
   1.641 -    ///\e
   1.642 -    typedef typename M::Value Value;
   1.643 +    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   1.644 +    typedef typename Parent::Key Key;
   1.645 +    typedef typename Parent::Value Value;
   1.646  
   1.647      ///Constructor
   1.648      AbsMap(const M &_m) : m(_m) {};
   1.649 -    Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
   1.650 +    Value operator[](Key k) const {
   1.651 +      Value tmp = m[k]; 
   1.652 +      return tmp >= 0 ? tmp : -tmp;
   1.653 +    }
   1.654 +
   1.655    };
   1.656    
   1.657    ///Returns a \ref AbsMap class
   1.658  
   1.659    ///This function just returns a \ref AbsMap class.
   1.660    ///\relates AbsMap
   1.661 -  template<class M> 
   1.662 -  inline AbsMap<M> absMap(const M &m) 
   1.663 -  {
   1.664 -    return AbsMap<M>(m);
   1.665 +  template<typename M> 
   1.666 +  inline AbsMap<M, True> absMap(const M &m) {
   1.667 +    return AbsMap<M, True>(m);
   1.668    }
   1.669  
   1.670    ///Converts an STL style functor to a map
   1.671 @@ -714,17 +704,16 @@
   1.672    ///Parameter \c F is the type of the used functor.
   1.673    
   1.674  
   1.675 -  template<class K,class V,class F> 
   1.676 -  class FunctorMap
   1.677 -  {
   1.678 +  template<typename F, 
   1.679 +	   typename K = typename F::argument_type, 
   1.680 +	   typename V = typename F::result_type,
   1.681 +	   typename NC = False> 
   1.682 +  class FunctorMap : public MapBase<K, V, NC> {
   1.683      const F &f;
   1.684    public:
   1.685 -
   1.686 -    typedef True NeedCopy;
   1.687 -    ///\e
   1.688 -    typedef K Key;
   1.689 -    ///\e
   1.690 -    typedef V Value;
   1.691 +    typedef MapBase<K, V, NC> Parent;
   1.692 +    typedef typename Parent::Key Key;
   1.693 +    typedef typename Parent::Value Value;
   1.694  
   1.695      ///Constructor
   1.696      FunctorMap(const F &_f) : f(_f) {};
   1.697 @@ -737,12 +726,24 @@
   1.698    ///
   1.699    ///The third template parameter isn't necessary to be given.
   1.700    ///\relates FunctorMap
   1.701 -  template<class K,class V, class F>
   1.702 -  inline FunctorMap<K,V,F> functorMap(const F &f) 
   1.703 -  {
   1.704 -    return FunctorMap<K,V,F>(f);
   1.705 +  template<typename K, typename V, typename F> inline 
   1.706 +  FunctorMap<F, K, V, True> functorMap(const F &f) {
   1.707 +    return FunctorMap<F, K, V, True>(f);
   1.708    }
   1.709  
   1.710 +  template <typename F> inline 
   1.711 +  FunctorMap<F, typename F::argument_type, typename F::result_type, True> 
   1.712 +  functorMap(const F &f) {
   1.713 +    return functorMap<typename F::argument_type, 
   1.714 +      typename F::result_type, F>(f);
   1.715 +  }
   1.716 +
   1.717 +  template <typename K, typename V> inline 
   1.718 +  FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
   1.719 +    return functorMap<K, V, V (*)(K)>(f);
   1.720 +  }
   1.721 +
   1.722 +
   1.723    ///Converts a map to an STL style (unary) functor
   1.724  
   1.725    ///This class Converts a map to an STL style (unary) functor.
   1.726 @@ -752,21 +753,18 @@
   1.727    ///a ususal \ref concept::ReadMap "readable map",
   1.728    ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
   1.729  
   1.730 -  template<class M> 
   1.731 -  class MapFunctor
   1.732 -  {
   1.733 +  template <typename M, typename NC = False> 
   1.734 +  class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
   1.735      typename SmartConstReference<M>::Type m;
   1.736    public:
   1.737 +    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   1.738 +    typedef typename Parent::Key Key;
   1.739 +    typedef typename Parent::Value Value;
   1.740  
   1.741 -    typedef True NeedCopy;
   1.742      ///\e
   1.743      typedef typename M::Key argument_type;
   1.744      ///\e
   1.745      typedef typename M::Value result_type;
   1.746 -    ///\e
   1.747 -    typedef typename M::Key Key;
   1.748 -    ///\e
   1.749 -    typedef typename M::Value Value;
   1.750  
   1.751      ///Constructor
   1.752      MapFunctor(const M &_m) : m(_m) {};
   1.753 @@ -780,10 +778,9 @@
   1.754  
   1.755    ///This function just returns a \ref MapFunctor class.
   1.756    ///\relates MapFunctor
   1.757 -  template<class M> 
   1.758 -  inline MapFunctor<M> mapFunctor(const M &m) 
   1.759 -  {
   1.760 -    return MapFunctor<M>(m);
   1.761 +  template<typename M> 
   1.762 +  inline MapFunctor<M, True> mapFunctor(const M &m) {
   1.763 +    return MapFunctor<M, True>(m);
   1.764    }
   1.765  
   1.766  
   1.767 @@ -798,23 +795,19 @@
   1.768    ///The \c Key and \c Value will be inherited from \c M1.
   1.769    ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   1.770  
   1.771 -  template<class M1,class M2> 
   1.772 -  class ForkMap
   1.773 -  {
   1.774 +  template<typename  M1, typename M2, typename NC = False> 
   1.775 +  class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   1.776      typename SmartConstReference<M1>::Type m1;
   1.777      typename SmartConstReference<M2>::Type m2;
   1.778    public:
   1.779 -
   1.780 -    typedef True NeedCopy;
   1.781 -    ///\e
   1.782 -    typedef typename M1::Key Key;
   1.783 -    ///\e
   1.784 -    typedef typename M1::Value Value;
   1.785 +    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   1.786 +    typedef typename Parent::Key Key;
   1.787 +    typedef typename Parent::Value Value;
   1.788  
   1.789      ///Constructor
   1.790      ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   1.791      Value operator[](Key k) const {return m1[k];}
   1.792 -    void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);}
   1.793 +    //    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
   1.794    };
   1.795    
   1.796    ///Returns an \ref ForkMap class
   1.797 @@ -824,10 +817,9 @@
   1.798    ///
   1.799    ///\relates ForkMap
   1.800    ///\todo Wrong scope in Doxygen when \c \\relates is used
   1.801 -  template<class M1,class M2> 
   1.802 -  inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2) 
   1.803 -  {
   1.804 -    return ForkMap<M1,M2>(m1,m2);
   1.805 +  template <typename M1, typename M2> 
   1.806 +  inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
   1.807 +    return ForkMap<M1, M2, True>(m1,m2);
   1.808    }
   1.809  
   1.810  
   1.811 @@ -842,17 +834,13 @@
   1.812    ///given map. Its \c Key and will be inherited from \c M,
   1.813    ///its Value is <tt>bool</tt>.
   1.814  
   1.815 -  template<class M> 
   1.816 -  class NotMap
   1.817 -  {
   1.818 +  template <typename M, typename NC = False> 
   1.819 +  class NotMap : public MapBase<typename M::Key, bool, NC> {
   1.820      typename SmartConstReference<M>::Type m;
   1.821    public:
   1.822 -
   1.823 -    typedef True NeedCopy;
   1.824 -    ///\e
   1.825 -    typedef typename M::Key Key;
   1.826 -    ///\e
   1.827 -    typedef bool Value;
   1.828 +    typedef MapBase<typename M::Key, bool, NC> Parent;
   1.829 +    typedef typename Parent::Key Key;
   1.830 +    typedef typename Parent::Value Value;
   1.831  
   1.832      ///Constructor
   1.833      NotMap(const M &_m) : m(_m) {};
   1.834 @@ -863,22 +851,15 @@
   1.835    
   1.836    ///This function just returns a \ref NotMap class.
   1.837    ///\relates NotMap
   1.838 -  template<class M> 
   1.839 -  inline NotMap<M> notMap(const M &m) 
   1.840 -  {
   1.841 -    return NotMap<M>(m);
   1.842 +  template <typename M> 
   1.843 +  inline NotMap<M, True> notMap(const M &m) {
   1.844 +    return NotMap<M, True>(m);
   1.845    }
   1.846  
   1.847  
   1.848  
   1.849  
   1.850  
   1.851 -
   1.852 -
   1.853 -
   1.854 -
   1.855 -
   1.856 -
   1.857    /// @}
   1.858  }
   1.859  
     2.1 --- a/test/map_test.h	Thu Sep 01 20:35:30 2005 +0000
     2.2 +++ b/test/map_test.h	Thu Sep 08 14:34:50 2005 +0000
     2.3 @@ -49,6 +49,10 @@
     2.4        nodes.push_back(graph.addNode());
     2.5        map[nodes.back()] = 23;
     2.6      }
     2.7 +    map = constMap<Node>(12);
     2.8 +    for (int i = 0; i < (int)nodes.size(); ++i) {
     2.9 +      check(map[nodes[i]] == 12, "Wrong map constructor.");      
    2.10 +    }    
    2.11      graph.clear();
    2.12      nodes.clear();
    2.13    }
    2.14 @@ -86,6 +90,10 @@
    2.15  	map[edges.back()] = 23;
    2.16        }
    2.17      }
    2.18 +    map = constMap<Edge>(12);
    2.19 +    for (int i = 0; i < (int)edges.size(); ++i) {
    2.20 +      check(map[edges[i]] == 12, "Wrong map constructor.");      
    2.21 +    }    
    2.22      graph.clear();
    2.23      edges.clear();    
    2.24    }
     3.1 --- a/test/maps_test.cc	Thu Sep 01 20:35:30 2005 +0000
     3.2 +++ b/test/maps_test.cc	Thu Sep 08 14:34:50 2005 +0000
     3.3 @@ -9,14 +9,19 @@
     3.4  
     3.5  struct A {};
     3.6  struct B {};
     3.7 -class F
     3.8 -{
     3.9 +
    3.10 +class F {
    3.11  public:
    3.12 +  typedef A argument_type;
    3.13 +  typedef B result_type;
    3.14 +
    3.15    B operator()(const A &) const {return B();}
    3.16  };
    3.17  
    3.18  int func(A) {return 3;}
    3.19  
    3.20 +int binc(int, B) {return 4;}
    3.21 +
    3.22  typedef ReadMap<A,double> DoubleMap;
    3.23  
    3.24  int main()
    3.25 @@ -38,7 +43,7 @@
    3.26    
    3.27    checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    3.28  
    3.29 -  checkConcept<ReadMap<A,B>, FunctorMap<A,B,F> >();
    3.30 +  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
    3.31  
    3.32    int a;
    3.33    
    3.34 @@ -46,11 +51,15 @@
    3.35    check(a==2,"Something is wrong with mapFunctor");
    3.36  
    3.37    B b;
    3.38 -  b=functorMap<A,B>(F())[A()];
    3.39 +  b=functorMap(F())[A()];
    3.40  
    3.41 -  a=functorMap<A,int>(&func)[A()];
    3.42 +  a=functorMap(&func)[A()];
    3.43    check(a==3,"Something is wrong with functorMap");
    3.44  
    3.45 +  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
    3.46 +  check(a==4,"Something is wrong with combineMap");
    3.47 +  
    3.48 +
    3.49    std::cout << __FILE__ ": All tests passed.\n";
    3.50    
    3.51    return 0;