lemon/maps.h
changeset 2583 7216b6a52ab9
parent 2553 bfced05fa852
equal deleted inserted replaced
32:f293408523d3 33:9878f259a295
    42   /// Base class of maps.
    42   /// Base class of maps.
    43   /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    43   /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    44   template<typename K, typename T>
    44   template<typename K, typename T>
    45   class MapBase {
    45   class MapBase {
    46   public:
    46   public:
    47     ///\e
    47     /// The key type of the map.
    48     typedef K Key;
    48     typedef K Key;
    49     ///\e
    49     /// The value type of the map. (The type of objects associated with the keys).
    50     typedef T Value;
    50     typedef T Value;
    51   };
    51   };
    52 
    52 
    53   /// Null map. (a.k.a. DoNothingMap)
    53   /// Null map. (a.k.a. DoNothingMap)
    54 
    54 
    55   /// If you have to provide a map only for its type definitions,
    55   /// This map can be used if you have to provide a map only for
    56   /// or if you have to provide a writable map, but
    56   /// its type definitions, or if you have to provide a writable map, 
    57   /// data written to it will sent to <tt>/dev/null</tt>...
    57   /// but data written to it is not required (i.e. it will be sent to 
       
    58   /// <tt>/dev/null</tt>).
    58   template<typename K, typename T>
    59   template<typename K, typename T>
    59   class NullMap : public MapBase<K, T> {
    60   class NullMap : public MapBase<K, T> {
    60   public:
    61   public:
    61     typedef MapBase<K, T> Parent;
    62     typedef MapBase<K, T> Parent;
    62     typedef typename Parent::Key Key;
    63     typedef typename Parent::Key Key;
    66     T operator[](const K&) const { return T(); }
    67     T operator[](const K&) const { return T(); }
    67     /// Absorbs the value.
    68     /// Absorbs the value.
    68     void set(const K&, const T&) {}
    69     void set(const K&, const T&) {}
    69   };
    70   };
    70 
    71 
       
    72   ///Returns a \c NullMap class
       
    73 
       
    74   ///This function just returns a \c NullMap class.
       
    75   ///\relates NullMap
    71   template <typename K, typename V> 
    76   template <typename K, typename V> 
    72   NullMap<K, V> nullMap() {
    77   NullMap<K, V> nullMap() {
    73     return NullMap<K, V>();
    78     return NullMap<K, V>();
    74   }
    79   }
    75 
    80 
    76 
    81 
    77   /// Constant map.
    82   /// Constant map.
    78 
    83 
    79   /// This is a readable map which assigns a specified value to each key.
    84   /// This is a \ref concepts::ReadMap "readable" map which assigns a 
    80   /// In other aspects it is equivalent to the \c NullMap.
    85   /// specified value to each key.
       
    86   /// In other aspects it is equivalent to \c NullMap.
    81   template<typename K, typename T>
    87   template<typename K, typename T>
    82   class ConstMap : public MapBase<K, T> {
    88   class ConstMap : public MapBase<K, T> {
    83   private:
    89   private:
    84     T v;
    90     T v;
    85   public:
    91   public:
    88     typedef typename Parent::Key Key;
    94     typedef typename Parent::Key Key;
    89     typedef typename Parent::Value Value;
    95     typedef typename Parent::Value Value;
    90 
    96 
    91     /// Default constructor
    97     /// Default constructor
    92 
    98 
       
    99     /// Default constructor.
    93     /// The value of the map will be uninitialized. 
   100     /// The value of the map will be uninitialized. 
    94     /// (More exactly it will be default constructed.)
   101     /// (More exactly it will be default constructed.)
    95     ConstMap() {}
   102     ConstMap() {}
    96     ///\e
   103     
    97 
   104     /// Constructor with specified initial value
    98     /// \param _v The initial value of the map.
   105 
    99     ///
   106     /// Constructor with specified initial value.
       
   107     /// \param _v is the initial value of the map.
   100     ConstMap(const T &_v) : v(_v) {}
   108     ConstMap(const T &_v) : v(_v) {}
   101     
   109     
   102     ///\e
   110     ///\e
   103     T operator[](const K&) const { return v; }
   111     T operator[](const K&) const { return v; }
   104 
   112 
   129   template<typename T, T v>
   137   template<typename T, T v>
   130   struct Const { };
   138   struct Const { };
   131 
   139 
   132   /// Constant map with inlined constant value.
   140   /// Constant map with inlined constant value.
   133 
   141 
   134   /// This is a readable map which assigns a specified value to each key.
   142   /// This is a \ref concepts::ReadMap "readable" map which assigns a 
   135   /// In other aspects it is equivalent to the \c NullMap.
   143   /// specified value to each key.
       
   144   /// In other aspects it is equivalent to \c NullMap.
   136   template<typename K, typename V, V v>
   145   template<typename K, typename V, V v>
   137   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
   146   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
   138   public:
   147   public:
   139     typedef MapBase<K, V> Parent;
   148     typedef MapBase<K, V> Parent;
   140     typedef typename Parent::Key Key;
   149     typedef typename Parent::Key Key;
   145     V operator[](const K&) const { return v; }
   154     V operator[](const K&) const { return v; }
   146     ///\e
   155     ///\e
   147     void set(const K&, const V&) { }
   156     void set(const K&, const V&) { }
   148   };
   157   };
   149 
   158 
   150   ///Returns a \c ConstMap class
   159   ///Returns a \c ConstMap class with inlined value
   151 
   160 
   152   ///This function just returns a \c ConstMap class with inlined value.
   161   ///This function just returns a \c ConstMap class with inlined value.
   153   ///\relates ConstMap
   162   ///\relates ConstMap
   154   template<typename K, typename V, V v> 
   163   template<typename K, typename V, V v> 
   155   inline ConstMap<K, Const<V, v> > constMap() {
   164   inline ConstMap<K, Const<V, v> > constMap() {
   156     return ConstMap<K, Const<V, v> >();
   165     return ConstMap<K, Const<V, v> >();
   157   }
   166   }
   158 
   167 
   159   ///Map based on std::map
   168   ///Map based on \c std::map
   160 
   169 
   161   ///This is essentially a wrapper for \c std::map. With addition that
   170   ///This is essentially a wrapper for \c std::map with addition that
   162   ///you can specify a default value different from \c Value() .
   171   ///you can specify a default value different from \c Value() .
       
   172   ///It meets the \ref concepts::ReferenceMap "ReferenceMap" concept.
   163   template <typename K, typename T, typename Compare = std::less<K> >
   173   template <typename K, typename T, typename Compare = std::less<K> >
   164   class StdMap {
   174   class StdMap : public MapBase<K, T> {
   165     template <typename K1, typename T1, typename C1>
   175     template <typename K1, typename T1, typename C1>
   166     friend class StdMap;
   176     friend class StdMap;
   167   public:
   177   public:
   168 
   178 
       
   179     typedef MapBase<K, T> Parent;
       
   180     ///Key type
       
   181     typedef typename Parent::Key Key;
       
   182     ///Value type
       
   183     typedef typename Parent::Value Value;
       
   184     ///Reference Type
       
   185     typedef T& Reference;
       
   186     ///Const reference type
       
   187     typedef const T& ConstReference;
       
   188 
   169     typedef True ReferenceMapTag;
   189     typedef True ReferenceMapTag;
   170     ///\e
       
   171     typedef K Key;
       
   172     ///\e
       
   173     typedef T Value;
       
   174     ///\e
       
   175     typedef T& Reference;
       
   176     ///\e
       
   177     typedef const T& ConstReference;
       
   178 
   190 
   179   private:
   191   private:
   180     
   192     
   181     typedef std::map<K, T, Compare> Map;
   193     typedef std::map<K, T, Compare> Map;
   182     Value _value;
   194     Value _value;
   184 
   196 
   185   public:
   197   public:
   186 
   198 
   187     /// Constructor with specified default value
   199     /// Constructor with specified default value
   188     StdMap(const T& value = T()) : _value(value) {}
   200     StdMap(const T& value = T()) : _value(value) {}
   189     /// \brief Constructs the map from an appropriate std::map, and explicitly
   201     /// \brief Constructs the map from an appropriate \c std::map, and 
   190     /// specifies a default value.
   202     /// explicitly specifies a default value.
   191     template <typename T1, typename Comp1>
   203     template <typename T1, typename Comp1>
   192     StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
   204     StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
   193       : _map(map.begin(), map.end()), _value(value) {}
   205       : _map(map.begin(), map.end()), _value(value) {}
   194     
   206     
   195     /// \brief Constructs a map from an other StdMap.
   207     /// \brief Constructs a map from an other \ref StdMap.
   196     template<typename T1, typename Comp1>
   208     template<typename T1, typename Comp1>
   197     StdMap(const StdMap<Key, T1, Comp1> &c) 
   209     StdMap(const StdMap<Key, T1, Comp1> &c) 
   198       : _map(c._map.begin(), c._map.end()), _value(c._value) {}
   210       : _map(c._map.begin(), c._map.end()), _value(c._value) {}
   199 
   211 
   200   private:
   212   private:
   240     struct rebind {
   252     struct rebind {
   241       typedef StdMap<Key, T1, C1> other;
   253       typedef StdMap<Key, T1, C1> other;
   242     };
   254     };
   243   };
   255   };
   244 
   256 
   245   /// \brief Map for storing values for the range \c [0..size-1] range keys
   257   ///Returns a \c StdMap class
   246   ///
   258 
   247   /// The current map has the \c [0..size-1] keyset and the values
   259   ///This function just returns a \c StdMap class with specified 
       
   260   ///default value.
       
   261   ///\relates StdMap
       
   262   template<typename K, typename V, typename Compare> 
       
   263   inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
       
   264     return StdMap<K, V, Compare>(value);
       
   265   }
       
   266   
       
   267   template<typename K, typename V> 
       
   268   inline StdMap<K, V, std::less<K> > stdMap(const V& value = V()) {
       
   269     return StdMap<K, V, std::less<K> >(value);
       
   270   }
       
   271   
       
   272   ///Returns a \c StdMap class created from an appropriate \c std::map
       
   273 
       
   274   ///This function just returns a \c StdMap class created from an 
       
   275   ///appropriate \c std::map.
       
   276   ///\relates StdMap
       
   277   template<typename K, typename V, typename Compare> 
       
   278   inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 
       
   279                                        const V& value = V() ) {
       
   280     return StdMap<K, V, Compare>(map, value);
       
   281   }
       
   282 
       
   283   /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
       
   284   ///
       
   285   /// This map has the <tt>[0..size-1]</tt> keyset and the values
   248   /// are stored in a \c std::vector<T>  container. It can be used with
   286   /// are stored in a \c std::vector<T>  container. It can be used with
   249   /// some data structures, for example \c UnionFind, \c BinHeap, when 
   287   /// some data structures, for example \c UnionFind, \c BinHeap, when 
   250   /// the used items are small integer numbers.
   288   /// the used items are small integer numbers.
   251   template <typename T>
   289   template <typename T>
   252   class IntegerMap {
   290   class IntegerMap : public MapBase<int, T> {
   253 
   291 
   254     template <typename T1>
   292     template <typename T1>
   255     friend class IntegerMap;
   293     friend class IntegerMap;
   256 
   294 
   257   public:
   295   public:
   258 
   296 
       
   297     typedef MapBase<int, T> Parent;
       
   298     ///\e
       
   299     typedef typename Parent::Key Key;
       
   300     ///\e
       
   301     typedef typename Parent::Value Value;
       
   302     ///\e
       
   303     typedef T& Reference;
       
   304     ///\e
       
   305     typedef const T& ConstReference;
       
   306 
   259     typedef True ReferenceMapTag;
   307     typedef True ReferenceMapTag;
   260     ///\e
       
   261     typedef int Key;
       
   262     ///\e
       
   263     typedef T Value;
       
   264     ///\e
       
   265     typedef T& Reference;
       
   266     ///\e
       
   267     typedef const T& ConstReference;
       
   268 
   308 
   269   private:
   309   private:
   270     
   310     
   271     typedef std::vector<T> Vector;
   311     typedef std::vector<T> Vector;
   272     Vector _vector;
   312     Vector _vector;
   274   public:
   314   public:
   275 
   315 
   276     /// Constructor with specified default value
   316     /// Constructor with specified default value
   277     IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
   317     IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
   278 
   318 
   279     /// \brief Constructs the map from an appropriate std::vector.
   319     /// \brief Constructs the map from an appropriate \c std::vector.
   280     template <typename T1>
   320     template <typename T1>
   281     IntegerMap(const std::vector<T1>& vector) 
   321     IntegerMap(const std::vector<T1>& vector) 
   282       : _vector(vector.begin(), vector.end()) {}
   322       : _vector(vector.begin(), vector.end()) {}
   283     
   323     
   284     /// \brief Constructs a map from an other IntegerMap.
   324     /// \brief Constructs a map from an other \ref IntegerMap.
   285     template <typename T1>
   325     template <typename T1>
   286     IntegerMap(const IntegerMap<T1> &c) 
   326     IntegerMap(const IntegerMap<T1> &c) 
   287       : _vector(c._vector.begin(), c._vector.end()) {}
   327       : _vector(c._vector.begin(), c._vector.end()) {}
   288 
   328 
   289     /// \brief Resize the container
   329     /// \brief Resize the container
   312       _vector[k] = t;
   352       _vector[k] = t;
   313     }
   353     }
   314 
   354 
   315   };
   355   };
   316 
   356 
       
   357   ///Returns an \c IntegerMap class
       
   358 
       
   359   ///This function just returns an \c IntegerMap class.
       
   360   ///\relates IntegerMap
       
   361   template<typename T>
       
   362   inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
       
   363     return IntegerMap<T>(size, value);
       
   364   }
       
   365 
   317   /// @}
   366   /// @}
   318 
   367 
   319   /// \addtogroup map_adaptors
   368   /// \addtogroup map_adaptors
   320   /// @{
   369   /// @{
   321 
   370 
   322   /// \brief Identity mapping.
   371   /// \brief Identity map.
   323   ///
   372   ///
   324   /// This mapping gives back the given key as value without any
   373   /// This map gives back the given key as value without any
   325   /// modification. 
   374   /// modification. 
   326   template <typename T>
   375   template <typename T>
   327   class IdentityMap : public MapBase<T, T> {
   376   class IdentityMap : public MapBase<T, T> {
   328   public:
   377   public:
   329     typedef MapBase<T, T> Parent;
   378     typedef MapBase<T, T> Parent;
   344   inline IdentityMap<T> identityMap() {
   393   inline IdentityMap<T> identityMap() {
   345     return IdentityMap<T>();
   394     return IdentityMap<T>();
   346   }
   395   }
   347   
   396   
   348 
   397 
   349   ///Convert the \c Value of a map to another type.
   398   ///\brief Convert the \c Value of a map to another type using
   350 
   399   ///the default conversion.
   351   ///This \c concepts::ReadMap "read only map"
   400   ///
   352   ///converts the \c Value of a maps to type \c T.
   401   ///This \ref concepts::ReadMap "read only map"
       
   402   ///converts the \c Value of a map to type \c T.
   353   ///Its \c Key is inherited from \c M.
   403   ///Its \c Key is inherited from \c M.
   354   template <typename M, typename T> 
   404   template <typename M, typename T> 
   355   class ConvertMap : public MapBase<typename M::Key, T> {
   405   class ConvertMap : public MapBase<typename M::Key, T> {
   356     const M& m;
   406     const M& m;
   357   public:
   407   public:
   363 
   413 
   364     ///Constructor
   414     ///Constructor
   365     ///\param _m is the underlying map
   415     ///\param _m is the underlying map
   366     ConvertMap(const M &_m) : m(_m) {};
   416     ConvertMap(const M &_m) : m(_m) {};
   367 
   417 
   368     /// \brief The subscript operator.
   418     ///\e
   369     ///
       
   370     /// The subscript operator.
       
   371     /// \param k The key
       
   372     /// \return The target of the edge 
       
   373     Value operator[](const Key& k) const {return m[k];}
   419     Value operator[](const Key& k) const {return m[k];}
   374   };
   420   };
   375   
   421   
   376   ///Returns an \c ConvertMap class
   422   ///Returns a \c ConvertMap class
   377 
   423 
   378   ///This function just returns an \c ConvertMap class.
   424   ///This function just returns a \c ConvertMap class.
   379   ///\relates ConvertMap
   425   ///\relates ConvertMap
   380   template<typename T, typename M>
   426   template<typename T, typename M>
   381   inline ConvertMap<M, T> convertMap(const M &m) {
   427   inline ConvertMap<M, T> convertMap(const M &m) {
   382     return ConvertMap<M, T>(m);
   428     return ConvertMap<M, T>(m);
   383   }
   429   }
   384 
   430 
   385   ///Simple wrapping of the map
   431   ///Simple wrapping of a map
   386 
   432 
   387   ///This \c concepts::ReadMap "read only map" returns the simple
   433   ///This \ref concepts::ReadMap "read only map" returns the simple
   388   ///wrapping of the given map. Sometimes the reference maps cannot be
   434   ///wrapping of the given map. Sometimes the reference maps cannot be
   389   ///combined with simple read maps. This map adaptor wraps the given
   435   ///combined with simple read maps. This map adaptor wraps the given
   390   ///map to simple read map.
   436   ///map to simple read map.
       
   437   ///
       
   438   ///\sa SimpleWriteMap
       
   439   ///
       
   440   /// \todo Revise the misleading name 
   391   template<typename M> 
   441   template<typename M> 
   392   class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
   442   class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
   393     const M& m;
   443     const M& m;
   394 
   444 
   395   public:
   445   public:
   401     SimpleMap(const M &_m) : m(_m) {};
   451     SimpleMap(const M &_m) : m(_m) {};
   402     ///\e
   452     ///\e
   403     Value operator[](Key k) const {return m[k];}
   453     Value operator[](Key k) const {return m[k];}
   404   };
   454   };
   405 
   455 
   406   ///Simple writeable wrapping of the map
   456   ///Returns a \c SimpleMap class
   407 
   457 
   408   ///This \c concepts::ReadMap "read only map" returns the simple
   458   ///This function just returns a \c SimpleMap class.
       
   459   ///\relates SimpleMap
       
   460   template<typename M>
       
   461   inline SimpleMap<M> simpleMap(const M &m) {
       
   462     return SimpleMap<M>(m);
       
   463   }
       
   464 
       
   465   ///Simple writable wrapping of a map
       
   466 
       
   467   ///This \ref concepts::ReadWriteMap "read-write map" returns the simple
   409   ///wrapping of the given map. Sometimes the reference maps cannot be
   468   ///wrapping of the given map. Sometimes the reference maps cannot be
   410   ///combined with simple read-write maps. This map adaptor wraps the
   469   ///combined with simple read-write maps. This map adaptor wraps the
   411   ///given map to simple read-write map.
   470   ///given map to simple read-write map.
       
   471   ///
       
   472   ///\sa SimpleMap
       
   473   ///
       
   474   /// \todo Revise the misleading name
   412   template<typename M> 
   475   template<typename M> 
   413   class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   476   class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   414     M& m;
   477     M& m;
   415 
   478 
   416   public:
   479   public:
   424     Value operator[](Key k) const {return m[k];}
   487     Value operator[](Key k) const {return m[k];}
   425     ///\e
   488     ///\e
   426     void set(Key k, const Value& c) { m.set(k, c); }
   489     void set(Key k, const Value& c) { m.set(k, c); }
   427   };
   490   };
   428 
   491 
       
   492   ///Returns a \c SimpleWriteMap class
       
   493 
       
   494   ///This function just returns a \c SimpleWriteMap class.
       
   495   ///\relates SimpleWriteMap
       
   496   template<typename M>
       
   497   inline SimpleWriteMap<M> simpleWriteMap(M &m) {
       
   498     return SimpleWriteMap<M>(m);
       
   499   }
       
   500 
   429   ///Sum of two maps
   501   ///Sum of two maps
   430 
   502 
   431   ///This \c concepts::ReadMap "read only map" returns the sum of the two
   503   ///This \ref concepts::ReadMap "read only map" returns the sum of the two
   432   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   504   ///given maps.
   433   ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   505   ///Its \c Key and \c Value are inherited from \c M1.
   434 
   506   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   435   template<typename M1, typename M2> 
   507   template<typename M1, typename M2> 
   436   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
   508   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
   437     const M1& m1;
   509     const M1& m1;
   438     const M2& m2;
   510     const M2& m2;
   439 
   511 
   459     return AddMap<M1, M2>(m1,m2);
   531     return AddMap<M1, M2>(m1,m2);
   460   }
   532   }
   461 
   533 
   462   ///Shift a map with a constant.
   534   ///Shift a map with a constant.
   463 
   535 
   464   ///This \c concepts::ReadMap "read only map" returns the sum of the
   536   ///This \ref concepts::ReadMap "read only map" returns the sum of the
   465   ///given map and a constant value.
   537   ///given map and a constant value.
   466   ///Its \c Key and \c Value is inherited from \c M.
   538   ///Its \c Key and \c Value is inherited from \c M.
   467   ///
   539   ///
   468   ///Actually,
   540   ///Actually,
   469   ///\code
   541   ///\code
   470   ///  ShiftMap<X> sh(x,v);
   542   ///  ShiftMap<X> sh(x,v);
   471   ///\endcode
   543   ///\endcode
   472   ///is equivalent with
   544   ///is equivalent to
   473   ///\code
   545   ///\code
   474   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   546   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   475   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
   547   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
   476   ///\endcode
   548   ///\endcode
       
   549   ///
       
   550   ///\sa ShiftWriteMap
   477   template<typename M, typename C = typename M::Value> 
   551   template<typename M, typename C = typename M::Value> 
   478   class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
   552   class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
   479     const M& m;
   553     const M& m;
   480     C v;
   554     C v;
   481   public:
   555   public:
   491     ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   565     ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   492     ///\e
   566     ///\e
   493     Value operator[](Key k) const {return m[k] + v;}
   567     Value operator[](Key k) const {return m[k] + v;}
   494   };
   568   };
   495 
   569 
   496   ///Shift a map with a constant.
   570   ///Shift a map with a constant (ReadWrite version).
   497 
   571 
   498   ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the
   572   ///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the
   499   ///given map and a constant value. It makes also possible to write the map.
   573   ///given map and a constant value. It makes also possible to write the map.
   500   ///Its \c Key and \c Value is inherited from \c M.
   574   ///Its \c Key and \c Value are inherited from \c M.
   501   ///
   575   ///
   502   ///Actually,
   576   ///\sa ShiftMap
   503   ///\code
       
   504   ///  ShiftMap<X> sh(x,v);
       
   505   ///\endcode
       
   506   ///is equivalent with
       
   507   ///\code
       
   508   ///  ConstMap<X::Key, X::Value> c_tmp(v);
       
   509   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
       
   510   ///\endcode
       
   511   template<typename M, typename C = typename M::Value> 
   577   template<typename M, typename C = typename M::Value> 
   512   class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
   578   class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
   513     M& m;
   579     M& m;
   514     C v;
   580     C v;
   515   public:
   581   public:
   527     Value operator[](Key k) const {return m[k] + v;}
   593     Value operator[](Key k) const {return m[k] + v;}
   528     /// \e
   594     /// \e
   529     void set(Key k, const Value& c) { m.set(k, c - v); }
   595     void set(Key k, const Value& c) { m.set(k, c - v); }
   530   };
   596   };
   531   
   597   
   532   ///Returns an \c ShiftMap class
   598   ///Returns a \c ShiftMap class
   533 
   599 
   534   ///This function just returns an \c ShiftMap class.
   600   ///This function just returns an \c ShiftMap class.
   535   ///\relates ShiftMap
   601   ///\relates ShiftMap
   536   template<typename M, typename C> 
   602   template<typename M, typename C> 
   537   inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
   603   inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
   538     return ShiftMap<M, C>(m,v);
   604     return ShiftMap<M, C>(m,v);
   539   }
   605   }
   540 
   606 
       
   607   ///Returns a \c ShiftWriteMap class
       
   608 
       
   609   ///This function just returns a \c ShiftWriteMap class.
       
   610   ///\relates ShiftWriteMap
   541   template<typename M, typename C> 
   611   template<typename M, typename C> 
   542   inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
   612   inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
   543     return ShiftWriteMap<M, C>(m,v);
   613     return ShiftWriteMap<M, C>(m,v);
   544   }
   614   }
   545 
   615 
   546   ///Difference of two maps
   616   ///Difference of two maps
   547 
   617 
   548   ///This \c concepts::ReadMap "read only map" returns the difference
   618   ///This \ref concepts::ReadMap "read only map" returns the difference
   549   ///of the values of the two
   619   ///of the values of the two given maps.
   550   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   620   ///Its \c Key and \c Value are inherited from \c M1.
   551   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   621   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   552 
   622 
   553   template<typename M1, typename M2> 
   623   template<typename M1, typename M2> 
   554   class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
   624   class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
   555     const M1& m1;
   625     const M1& m1;
   575     return SubMap<M1, M2>(m1, m2);
   645     return SubMap<M1, M2>(m1, m2);
   576   }
   646   }
   577 
   647 
   578   ///Product of two maps
   648   ///Product of two maps
   579 
   649 
   580   ///This \c concepts::ReadMap "read only map" returns the product of the
   650   ///This \ref concepts::ReadMap "read only map" returns the product of the
   581   ///values of the two
   651   ///values of the two given maps.
   582   ///given
   652   ///Its \c Key and \c Value are inherited from \c M1.
   583   ///maps. Its \c Key and \c Value will be inherited from \c M1.
       
   584   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   653   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   585 
       
   586   template<typename M1, typename M2> 
   654   template<typename M1, typename M2> 
   587   class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
   655   class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
   588     const M1& m1;
   656     const M1& m1;
   589     const M2& m2;
   657     const M2& m2;
   590   public:
   658   public:
   605   template<typename M1, typename M2> 
   673   template<typename M1, typename M2> 
   606   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
   674   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
   607     return MulMap<M1, M2>(m1,m2);
   675     return MulMap<M1, M2>(m1,m2);
   608   }
   676   }
   609  
   677  
   610   ///Scales a maps with a constant.
   678   ///Scales a map with a constant.
   611 
   679 
   612   ///This \c concepts::ReadMap "read only map" returns the value of the
   680   ///This \ref concepts::ReadMap "read only map" returns the value of the
   613   ///given map multiplied from the left side with a constant value.
   681   ///given map multiplied from the left side with a constant value.
   614   ///Its \c Key and \c Value is inherited from \c M.
   682   ///Its \c Key and \c Value are inherited from \c M.
   615   ///
   683   ///
   616   ///Actually,
   684   ///Actually,
   617   ///\code
   685   ///\code
   618   ///  ScaleMap<X> sc(x,v);
   686   ///  ScaleMap<X> sc(x,v);
   619   ///\endcode
   687   ///\endcode
   620   ///is equivalent with
   688   ///is equivalent to
   621   ///\code
   689   ///\code
   622   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   690   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   623   ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
   691   ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
   624   ///\endcode
   692   ///\endcode
       
   693   ///
       
   694   ///\sa ScaleWriteMap
   625   template<typename M, typename C = typename M::Value> 
   695   template<typename M, typename C = typename M::Value> 
   626   class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
   696   class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
   627     const M& m;
   697     const M& m;
   628     C v;
   698     C v;
   629   public:
   699   public:
   639     ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   709     ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
   640     /// \e
   710     /// \e
   641     Value operator[](Key k) const {return v * m[k];}
   711     Value operator[](Key k) const {return v * m[k];}
   642   };
   712   };
   643 
   713 
   644   ///Scales a maps with a constant.
   714   ///Scales a map with a constant (ReadWrite version).
   645 
   715 
   646   ///This \c concepts::ReadWriteMap "read-write map" returns the value of the
   716   ///This \ref concepts::ReadWriteMap "read-write map" returns the value of the
   647   ///given map multiplied from the left side with a constant value. It can
   717   ///given map multiplied from the left side with a constant value. It can
   648   ///be used as write map also if the given multiplier is not zero.
   718   ///also be used as write map if the \c / operator is defined between
   649   ///Its \c Key and \c Value is inherited from \c M.
   719   ///\c Value and \c C and the given multiplier is not zero.
       
   720   ///Its \c Key and \c Value are inherited from \c M.
       
   721   ///
       
   722   ///\sa ScaleMap
   650   template<typename M, typename C = typename M::Value> 
   723   template<typename M, typename C = typename M::Value> 
   651   class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   724   class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
   652     M& m;
   725     M& m;
   653     C v;
   726     C v;
   654   public:
   727   public:
   666     Value operator[](Key k) const {return v * m[k];}
   739     Value operator[](Key k) const {return v * m[k];}
   667     /// \e
   740     /// \e
   668     void set(Key k, const Value& c) { m.set(k, c / v);}
   741     void set(Key k, const Value& c) { m.set(k, c / v);}
   669   };
   742   };
   670   
   743   
   671   ///Returns an \c ScaleMap class
   744   ///Returns a \c ScaleMap class
   672 
   745 
   673   ///This function just returns an \c ScaleMap class.
   746   ///This function just returns a \c ScaleMap class.
   674   ///\relates ScaleMap
   747   ///\relates ScaleMap
   675   template<typename M, typename C> 
   748   template<typename M, typename C> 
   676   inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
   749   inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
   677     return ScaleMap<M, C>(m,v);
   750     return ScaleMap<M, C>(m,v);
   678   }
   751   }
   679 
   752 
       
   753   ///Returns a \c ScaleWriteMap class
       
   754 
       
   755   ///This function just returns a \c ScaleWriteMap class.
       
   756   ///\relates ScaleWriteMap
   680   template<typename M, typename C> 
   757   template<typename M, typename C> 
   681   inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
   758   inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
   682     return ScaleWriteMap<M, C>(m,v);
   759     return ScaleWriteMap<M, C>(m,v);
   683   }
   760   }
   684 
   761 
   685   ///Quotient of two maps
   762   ///Quotient of two maps
   686 
   763 
   687   ///This \c concepts::ReadMap "read only map" returns the quotient of the
   764   ///This \ref concepts::ReadMap "read only map" returns the quotient of the
   688   ///values of the two
   765   ///values of the two given maps.
   689   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   766   ///Its \c Key and \c Value are inherited from \c M1.
   690   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   767   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   691 
       
   692   template<typename M1, typename M2> 
   768   template<typename M1, typename M2> 
   693   class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
   769   class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
   694     const M1& m1;
   770     const M1& m1;
   695     const M2& m2;
   771     const M2& m2;
   696   public:
   772   public:
   713     return DivMap<M1, M2>(m1,m2);
   789     return DivMap<M1, M2>(m1,m2);
   714   }
   790   }
   715   
   791   
   716   ///Composition of two maps
   792   ///Composition of two maps
   717 
   793 
   718   ///This \c concepts::ReadMap "read only map" returns the composition of
   794   ///This \ref concepts::ReadMap "read only map" returns the composition of
   719   ///two
   795   ///two given maps.
   720   ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is
   796   ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2,
   721   ///of \c M2,
       
   722   ///then for
   797   ///then for
   723   ///\code
   798   ///\code
   724   ///  ComposeMap<M1, M2> cm(m1,m2);
   799   ///  ComposeMap<M1, M2> cm(m1,m2);
   725   ///\endcode
   800   ///\endcode
   726   /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
   801   /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
   727   ///
   802   ///
   728   ///Its \c Key is inherited from \c M2 and its \c Value is from
   803   ///Its \c Key is inherited from \c M2 and its \c Value is from \c M1.
   729   ///\c M1.
   804   ///\c M2::Value must be convertible to \c M1::Key.
   730   ///The \c M2::Value must be convertible to \c M1::Key.
   805   ///
       
   806   ///\sa CombineMap
       
   807   ///
   731   ///\todo Check the requirements.
   808   ///\todo Check the requirements.
   732   template <typename M1, typename M2> 
   809   template <typename M1, typename M2> 
   733   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
   810   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
   734     const M1& m1;
   811     const M1& m1;
   735     const M2& m2;
   812     const M2& m2;
   753   template <typename M1, typename M2> 
   830   template <typename M1, typename M2> 
   754   inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
   831   inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
   755     return ComposeMap<M1, M2>(m1,m2);
   832     return ComposeMap<M1, M2>(m1,m2);
   756   }
   833   }
   757   
   834   
   758   ///Combines of two maps using an STL (binary) functor.
   835   ///Combine of two maps using an STL (binary) functor.
   759 
   836 
   760   ///Combines of two maps using an STL (binary) functor.
   837   ///Combine of two maps using an STL (binary) functor.
   761   ///
   838   ///
   762   ///
   839   ///This \ref concepts::ReadMap "read only map" takes two maps and a
   763   ///This \c concepts::ReadMap "read only map" takes two maps and a
   840   ///binary functor and returns the composition of the two
   764   ///binary functor and returns the composition of
       
   765   ///the two
       
   766   ///given maps unsing the functor. 
   841   ///given maps unsing the functor. 
   767   ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
   842   ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
   768   ///and \c f is of \c F,
   843   ///and \c f is of \c F, then for
   769   ///then for
       
   770   ///\code
   844   ///\code
   771   ///  CombineMap<M1, M2,F,V> cm(m1,m2,f);
   845   ///  CombineMap<M1, M2,F,V> cm(m1,m2,f);
   772   ///\endcode
   846   ///\endcode
   773   /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
   847   /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
   774   ///
   848   ///
   775   ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
   849   ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
   776   ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
   850   ///\c M2::Value and \c M1::Value must be convertible to the corresponding
   777   ///input parameter of \c F and the return type of \c F must be convertible
   851   ///input parameter of \c F and the return type of \c F must be convertible
   778   ///to \c V.
   852   ///to \c V.
       
   853   ///
       
   854   ///\sa ComposeMap
       
   855   ///
   779   ///\todo Check the requirements.
   856   ///\todo Check the requirements.
   780   template<typename M1, typename M2, typename F,
   857   template<typename M1, typename M2, typename F,
   781 	   typename V = typename F::result_type> 
   858 	   typename V = typename F::result_type> 
   782   class CombineMap : public MapBase<typename M1::Key, V> {
   859   class CombineMap : public MapBase<typename M1::Key, V> {
   783     const M1& m1;
   860     const M1& m1;
   799 
   876 
   800   ///This function just returns a \c CombineMap class.
   877   ///This function just returns a \c CombineMap class.
   801   ///
   878   ///
   802   ///For example if \c m1 and \c m2 are both \c double valued maps, then 
   879   ///For example if \c m1 and \c m2 are both \c double valued maps, then 
   803   ///\code
   880   ///\code
   804   ///combineMap<double>(m1,m2,std::plus<double>())
   881   ///combineMap(m1,m2,std::plus<double>())
   805   ///\endcode
   882   ///\endcode
   806   ///is equivalent with
   883   ///is equivalent to
   807   ///\code
   884   ///\code
   808   ///addMap(m1,m2)
   885   ///addMap(m1,m2)
   809   ///\endcode
   886   ///\endcode
   810   ///
   887   ///
   811   ///This function is specialized for adaptable binary function
   888   ///This function is specialized for adaptable binary function
   812   ///classes and c++ functions.
   889   ///classes and C++ functions.
   813   ///
   890   ///
   814   ///\relates CombineMap
   891   ///\relates CombineMap
   815   template<typename M1, typename M2, typename F, typename V> 
   892   template<typename M1, typename M2, typename F, typename V> 
   816   inline CombineMap<M1, M2, F, V> 
   893   inline CombineMap<M1, M2, F, V> 
   817   combineMap(const M1& m1,const M2& m2, const F& f) {
   894   combineMap(const M1& m1,const M2& m2, const F& f) {
   830     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   907     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   831   }
   908   }
   832 
   909 
   833   ///Negative value of a map
   910   ///Negative value of a map
   834 
   911 
   835   ///This \c concepts::ReadMap "read only map" returns the negative
   912   ///This \ref concepts::ReadMap "read only map" returns the negative
   836   ///value of the
   913   ///value of the value returned by the given map.
   837   ///value returned by the
   914   ///Its \c Key and \c Value are inherited from \c M.
   838   ///given map. Its \c Key and \c Value will be inherited from \c M.
       
   839   ///The unary \c - operator must be defined for \c Value, of course.
   915   ///The unary \c - operator must be defined for \c Value, of course.
   840 
   916   ///
       
   917   ///\sa NegWriteMap
   841   template<typename M> 
   918   template<typename M> 
   842   class NegMap : public MapBase<typename M::Key, typename M::Value> {
   919   class NegMap : public MapBase<typename M::Key, typename M::Value> {
   843     const M& m;
   920     const M& m;
   844   public:
   921   public:
   845     typedef MapBase<typename M::Key, typename M::Value> Parent;
   922     typedef MapBase<typename M::Key, typename M::Value> Parent;
   850     NegMap(const M &_m) : m(_m) {};
   927     NegMap(const M &_m) : m(_m) {};
   851     /// \e
   928     /// \e
   852     Value operator[](Key k) const {return -m[k];}
   929     Value operator[](Key k) const {return -m[k];}
   853   };
   930   };
   854   
   931   
   855   ///Negative value of a map
   932   ///Negative value of a map (ReadWrite version)
   856 
   933 
   857   ///This \c concepts::ReadWriteMap "read-write map" returns the negative
   934   ///This \ref concepts::ReadWriteMap "read-write map" returns the negative
   858   ///value of the value returned by the
   935   ///value of the value returned by the given map.
   859   ///given map. Its \c Key and \c Value will be inherited from \c M.
   936   ///Its \c Key and \c Value are inherited from \c M.
   860   ///The unary \c - operator must be defined for \c Value, of course.
   937   ///The unary \c - operator must be defined for \c Value, of course.
   861 
   938   ///
       
   939   /// \sa NegMap
   862   template<typename M> 
   940   template<typename M> 
   863   class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
   941   class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
   864     M& m;
   942     M& m;
   865   public:
   943   public:
   866     typedef MapBase<typename M::Key, typename M::Value> Parent;
   944     typedef MapBase<typename M::Key, typename M::Value> Parent;
   882   template <typename M> 
   960   template <typename M> 
   883   inline NegMap<M> negMap(const M &m) {
   961   inline NegMap<M> negMap(const M &m) {
   884     return NegMap<M>(m);
   962     return NegMap<M>(m);
   885   }
   963   }
   886 
   964 
       
   965   ///Returns a \c NegWriteMap class
       
   966 
       
   967   ///This function just returns a \c NegWriteMap class.
       
   968   ///\relates NegWriteMap
   887   template <typename M> 
   969   template <typename M> 
   888   inline NegWriteMap<M> negMap(M &m) {
   970   inline NegWriteMap<M> negMap(M &m) {
   889     return NegWriteMap<M>(m);
   971     return NegWriteMap<M>(m);
   890   }
   972   }
   891 
   973 
   892   ///Absolute value of a map
   974   ///Absolute value of a map
   893 
   975 
   894   ///This \c concepts::ReadMap "read only map" returns the absolute value
   976   ///This \ref concepts::ReadMap "read only map" returns the absolute value
   895   ///of the
   977   ///of the value returned by the given map.
   896   ///value returned by the
   978   ///Its \c Key and \c Value are inherited from \c M. 
   897   ///given map. Its \c Key and \c Value will be inherited
   979   ///\c Value must be comparable to \c 0 and the unary \c -
   898   ///from <tt>M</tt>. <tt>Value</tt>
       
   899   ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
       
   900   ///operator must be defined for it, of course.
   980   ///operator must be defined for it, of course.
   901   ///
   981   ///
   902   ///\bug We need a unified way to handle the situation below:
   982   ///\bug We need a unified way to handle the situation below:
   903   ///\code
   983   ///\code
   904   ///  struct _UnConvertible {};
   984   ///  struct _UnConvertible {};
   928       return tmp >= 0 ? tmp : -tmp;
  1008       return tmp >= 0 ? tmp : -tmp;
   929     }
  1009     }
   930 
  1010 
   931   };
  1011   };
   932   
  1012   
   933   ///Returns a \c AbsMap class
  1013   ///Returns an \c AbsMap class
   934 
  1014 
   935   ///This function just returns a \c AbsMap class.
  1015   ///This function just returns an \c AbsMap class.
   936   ///\relates AbsMap
  1016   ///\relates AbsMap
   937   template<typename M> 
  1017   template<typename M> 
   938   inline AbsMap<M> absMap(const M &m) {
  1018   inline AbsMap<M> absMap(const M &m) {
   939     return AbsMap<M>(m);
  1019     return AbsMap<M>(m);
   940   }
  1020   }
   941 
  1021 
   942   ///Converts an STL style functor to a map
  1022   ///Converts an STL style functor to a map
   943 
  1023 
   944   ///This \c concepts::ReadMap "read only map" returns the value
  1024   ///This \ref concepts::ReadMap "read only map" returns the value
   945   ///of a
  1025   ///of a given functor.
   946   ///given map.
       
   947   ///
  1026   ///
   948   ///Template parameters \c K and \c V will become its
  1027   ///Template parameters \c K and \c V will become its
   949   ///\c Key and \c Value. They must be given explicitely
  1028   ///\c Key and \c Value. 
   950   ///because a functor does not provide such typedefs.
  1029   ///In most cases they have to be given explicitly because a 
       
  1030   ///functor typically does not provide \c argument_type and 
       
  1031   ///\c result_type typedefs.
   951   ///
  1032   ///
   952   ///Parameter \c F is the type of the used functor.
  1033   ///Parameter \c F is the type of the used functor.
       
  1034   ///
       
  1035   ///\sa MapFunctor
   953   template<typename F, 
  1036   template<typename F, 
   954 	   typename K = typename F::argument_type, 
  1037 	   typename K = typename F::argument_type, 
   955 	   typename V = typename F::result_type> 
  1038 	   typename V = typename F::result_type> 
   956   class FunctorMap : public MapBase<K, V> {
  1039   class FunctorMap : public MapBase<K, V> {
   957     F f;
  1040     F f;
   968   
  1051   
   969   ///Returns a \c FunctorMap class
  1052   ///Returns a \c FunctorMap class
   970 
  1053 
   971   ///This function just returns a \c FunctorMap class.
  1054   ///This function just returns a \c FunctorMap class.
   972   ///
  1055   ///
   973   ///It is specialized for adaptable function classes and
  1056   ///This function is specialized for adaptable binary function
   974   ///c++ functions.
  1057   ///classes and C++ functions.
       
  1058   ///
   975   ///\relates FunctorMap
  1059   ///\relates FunctorMap
   976   template<typename K, typename V, typename F> inline 
  1060   template<typename K, typename V, typename F> inline 
   977   FunctorMap<F, K, V> functorMap(const F &f) {
  1061   FunctorMap<F, K, V> functorMap(const F &f) {
   978     return FunctorMap<F, K, V>(f);
  1062     return FunctorMap<F, K, V>(f);
   979   }
  1063   }
   992 
  1076 
   993 
  1077 
   994   ///Converts a map to an STL style (unary) functor
  1078   ///Converts a map to an STL style (unary) functor
   995 
  1079 
   996   ///This class Converts a map to an STL style (unary) functor.
  1080   ///This class Converts a map to an STL style (unary) functor.
   997   ///that is it provides an <tt>operator()</tt> to read its values.
  1081   ///That is it provides an <tt>operator()</tt> to read its values.
   998   ///
  1082   ///
   999   ///For the sake of convenience it also works as
  1083   ///For the sake of convenience it also works as
  1000   ///a ususal \c concepts::ReadMap "readable map",
  1084   ///a ususal \ref concepts::ReadMap "readable map",
  1001   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
  1085   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
       
  1086   ///
       
  1087   ///\sa FunctorMap
  1002   template <typename M> 
  1088   template <typename M> 
  1003   class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
  1089   class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
  1004     const M& m;
  1090     const M& m;
  1005   public:
  1091   public:
  1006     typedef MapBase<typename M::Key, typename M::Value> Parent;
  1092     typedef MapBase<typename M::Key, typename M::Value> Parent;
  1025   template<typename M> 
  1111   template<typename M> 
  1026   inline MapFunctor<M> mapFunctor(const M &m) {
  1112   inline MapFunctor<M> mapFunctor(const M &m) {
  1027     return MapFunctor<M>(m);
  1113     return MapFunctor<M>(m);
  1028   }
  1114   }
  1029 
  1115 
  1030   ///Applies all map setting operations to two maps
  1116   ///Just readable version of \ref ForkWriteMap
  1031 
  1117 
  1032   ///This map has two \c concepts::ReadMap "readable map"
  1118   ///This map has two \ref concepts::ReadMap "readable map"
  1033   ///parameters and each read request will be passed just to the
  1119   ///parameters and each read request will be passed just to the
  1034   ///first map. This class is the just readable map type of the ForkWriteMap.
  1120   ///first map. This class is the just readable map type of \c ForkWriteMap.
  1035   ///
  1121   ///
  1036   ///The \c Key and \c Value will be inherited from \c M1.
  1122   ///The \c Key and \c Value are inherited from \c M1.
  1037   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
  1123   ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1.
       
  1124   ///
       
  1125   ///\sa ForkWriteMap
       
  1126 
  1038   template<typename  M1, typename M2> 
  1127   template<typename  M1, typename M2> 
  1039   class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
  1128   class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
  1040     const M1& m1;
  1129     const M1& m1;
  1041     const M2& m2;
  1130     const M2& m2;
  1042   public:
  1131   public:
  1051   };
  1140   };
  1052 
  1141 
  1053 
  1142 
  1054   ///Applies all map setting operations to two maps
  1143   ///Applies all map setting operations to two maps
  1055 
  1144 
  1056   ///This map has two \c concepts::WriteMap "writable map"
  1145   ///This map has two \ref concepts::WriteMap "writable map"
  1057   ///parameters and each write request will be passed to both of them.
  1146   ///parameters and each write request will be passed to both of them.
  1058   ///If \c M1 is also \c concepts::ReadMap "readable",
  1147   ///If \c M1 is also \ref concepts::ReadMap "readable",
  1059   ///then the read operations will return the
  1148   ///then the read operations will return the
  1060   ///corresponding values of \c M1.
  1149   ///corresponding values of \c M1.
  1061   ///
  1150   ///
  1062   ///The \c Key and \c Value will be inherited from \c M1.
  1151   ///The \c Key and \c Value are inherited from \c M1.
  1063   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
  1152   ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1.
       
  1153   ///
       
  1154   ///\sa ForkMap
  1064   template<typename  M1, typename M2> 
  1155   template<typename  M1, typename M2> 
  1065   class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
  1156   class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
  1066     M1& m1;
  1157     M1& m1;
  1067     M2& m2;
  1158     M2& m2;
  1068   public:
  1159   public:
  1076     Value operator[](Key k) const {return m1[k];}
  1167     Value operator[](Key k) const {return m1[k];}
  1077     ///\e
  1168     ///\e
  1078     void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
  1169     void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
  1079   };
  1170   };
  1080   
  1171   
  1081   ///Returns an \c ForkMap class
  1172   ///Returns a \c ForkMap class
  1082 
  1173 
  1083   ///This function just returns an \c ForkMap class.
  1174   ///This function just returns a \c ForkMap class.
  1084   ///
       
  1085   ///\relates ForkMap
  1175   ///\relates ForkMap
  1086   template <typename M1, typename M2> 
  1176   template <typename M1, typename M2> 
  1087   inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
  1177   inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
  1088     return ForkMap<M1, M2>(m1,m2);
  1178     return ForkMap<M1, M2>(m1,m2);
  1089   }
  1179   }
  1090 
  1180 
       
  1181   ///Returns a \c ForkWriteMap class
       
  1182 
       
  1183   ///This function just returns a \c ForkWriteMap class.
       
  1184   ///\relates ForkWriteMap
  1091   template <typename M1, typename M2> 
  1185   template <typename M1, typename M2> 
  1092   inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
  1186   inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
  1093     return ForkWriteMap<M1, M2>(m1,m2);
  1187     return ForkWriteMap<M1, M2>(m1,m2);
  1094   }
  1188   }
  1095 
  1189 
  1097   
  1191   
  1098   /* ************* BOOL MAPS ******************* */
  1192   /* ************* BOOL MAPS ******************* */
  1099   
  1193   
  1100   ///Logical 'not' of a map
  1194   ///Logical 'not' of a map
  1101   
  1195   
  1102   ///This bool \c concepts::ReadMap "read only map" returns the 
  1196   ///This bool \ref concepts::ReadMap "read only map" returns the 
  1103   ///logical negation of
  1197   ///logical negation of the value returned by the given map.
  1104   ///value returned by the
  1198   ///Its \c Key is inherited from \c M, its \c Value is \c bool.
  1105   ///given map. Its \c Key and will be inherited from \c M,
  1199   ///
  1106   ///its Value is <tt>bool</tt>.
  1200   ///\sa NotWriteMap
  1107   template <typename M> 
  1201   template <typename M> 
  1108   class NotMap : public MapBase<typename M::Key, bool> {
  1202   class NotMap : public MapBase<typename M::Key, bool> {
  1109     const M& m;
  1203     const M& m;
  1110   public:
  1204   public:
  1111     typedef MapBase<typename M::Key, bool> Parent;
  1205     typedef MapBase<typename M::Key, bool> Parent;
  1116     NotMap(const M &_m) : m(_m) {};
  1210     NotMap(const M &_m) : m(_m) {};
  1117     ///\e
  1211     ///\e
  1118     Value operator[](Key k) const {return !m[k];}
  1212     Value operator[](Key k) const {return !m[k];}
  1119   };
  1213   };
  1120 
  1214 
  1121   ///Logical 'not' of a map with writing possibility
  1215   ///Logical 'not' of a map (ReadWrie version)
  1122   
  1216   
  1123   ///This bool \c concepts::ReadWriteMap "read-write map" returns the 
  1217   ///This bool \ref concepts::ReadWriteMap "read-write map" returns the 
  1124   ///logical negation of value returned by the given map. When it is set,
  1218   ///logical negation of the value returned by the given map. When it is set,
  1125   ///the opposite value is set to the original map.
  1219   ///the opposite value is set to the original map.
  1126   ///Its \c Key and will be inherited from \c M,
  1220   ///Its \c Key is inherited from \c M, its \c Value is \c bool.
  1127   ///its Value is <tt>bool</tt>.
  1221   ///
       
  1222   ///\sa NotMap
  1128   template <typename M> 
  1223   template <typename M> 
  1129   class NotWriteMap : public MapBase<typename M::Key, bool> {
  1224   class NotWriteMap : public MapBase<typename M::Key, bool> {
  1130     M& m;
  1225     M& m;
  1131   public:
  1226   public:
  1132     typedef MapBase<typename M::Key, bool> Parent;
  1227     typedef MapBase<typename M::Key, bool> Parent;
  1148   template <typename M> 
  1243   template <typename M> 
  1149   inline NotMap<M> notMap(const M &m) {
  1244   inline NotMap<M> notMap(const M &m) {
  1150     return NotMap<M>(m);
  1245     return NotMap<M>(m);
  1151   }
  1246   }
  1152   
  1247   
       
  1248   ///Returns a \c NotWriteMap class
       
  1249   
       
  1250   ///This function just returns a \c NotWriteMap class.
       
  1251   ///\relates NotWriteMap
  1153   template <typename M> 
  1252   template <typename M> 
  1154   inline NotWriteMap<M> notMap(M &m) {
  1253   inline NotWriteMap<M> notMap(M &m) {
  1155     return NotWriteMap<M>(m);
  1254     return NotWriteMap<M>(m);
  1156   }
  1255   }
  1157 
  1256 
  1179     };
  1278     };
  1180 
  1279 
  1181   }
  1280   }
  1182   
  1281   
  1183 
  1282 
  1184   /// \brief Writable bool map for store each true assigned elements.
  1283   /// \brief Writable bool map for logging each \c true assigned element
  1185   ///
  1284   ///
  1186   /// Writable bool map to store each true assigned elements. It will
  1285   /// A \ref concepts::ReadWriteMap "read-write" bool map for logging 
  1187   /// copies all the keys set to true to the given iterator.
  1286   /// each \c true assigned element, i.e it copies all the keys set 
       
  1287   /// to \c true to the given iterator.
  1188   ///
  1288   ///
  1189   /// \note The container of the iterator should contain space 
  1289   /// \note The container of the iterator should contain space 
  1190   /// for each element.
  1290   /// for each element.
  1191   ///
  1291   ///
  1192   /// The next example shows how can you write the nodes directly
  1292   /// The following example shows how you can write the edges found by 
  1193   /// to the standard output.
  1293   /// the \ref Prim algorithm directly to the standard output.
  1194   ///\code
  1294   ///\code
  1195   /// typedef IdMap<UGraph, UEdge> UEdgeIdMap;
  1295   /// typedef IdMap<UGraph, UEdge> UEdgeIdMap;
  1196   /// UEdgeIdMap uedgeId(ugraph);
  1296   /// UEdgeIdMap uedgeId(ugraph);
  1197   ///
  1297   ///
  1198   /// typedef MapFunctor<UEdgeIdMap> UEdgeIdFunctor;
  1298   /// typedef MapFunctor<UEdgeIdMap> UEdgeIdFunctor;
  1201   /// StoreBoolMap<ostream_iterator<int>, UEdgeIdFunctor> 
  1301   /// StoreBoolMap<ostream_iterator<int>, UEdgeIdFunctor> 
  1202   ///   writerMap(ostream_iterator<int>(cout, " "), uedgeIdFunctor);
  1302   ///   writerMap(ostream_iterator<int>(cout, " "), uedgeIdFunctor);
  1203   ///
  1303   ///
  1204   /// prim(ugraph, cost, writerMap);
  1304   /// prim(ugraph, cost, writerMap);
  1205   ///\endcode
  1305   ///\endcode
       
  1306   ///
       
  1307   ///\sa BackInserterBoolMap 
       
  1308   ///\sa FrontInserterBoolMap 
       
  1309   ///\sa InserterBoolMap 
  1206   template <typename _Iterator, 
  1310   template <typename _Iterator, 
  1207             typename _Functor =
  1311             typename _Functor =
  1208             _maps_bits::Identity<typename _maps_bits::
  1312             _maps_bits::Identity<typename _maps_bits::
  1209                                  IteratorTraits<_Iterator>::Value> >
  1313                                  IteratorTraits<_Iterator>::Value> >
  1210   class StoreBoolMap {
  1314   class StoreBoolMap {
  1218 
  1322 
  1219     /// Constructor
  1323     /// Constructor
  1220     StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
  1324     StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
  1221       : _begin(it), _end(it), _functor(functor) {}
  1325       : _begin(it), _end(it), _functor(functor) {}
  1222 
  1326 
  1223     /// Gives back the given iterator set for the first time.
  1327     /// Gives back the given iterator set for the first key
  1224     Iterator begin() const {
  1328     Iterator begin() const {
  1225       return _begin;
  1329       return _begin;
  1226     }
  1330     }
  1227  
  1331  
  1228     /// Gives back the iterator after the last set operation.
  1332     /// Gives back the the 'after the last' iterator
  1229     Iterator end() const {
  1333     Iterator end() const {
  1230       return _end;
  1334       return _end;
  1231     }
  1335     }
  1232 
  1336 
  1233     /// Setter function of the map
  1337     /// The \c set function of the map
  1234     void set(const Key& key, Value value) const {
  1338     void set(const Key& key, Value value) const {
  1235       if (value) {
  1339       if (value) {
  1236 	*_end++ = _functor(key);
  1340 	*_end++ = _functor(key);
  1237       }
  1341       }
  1238     }
  1342     }
  1241     Iterator _begin;
  1345     Iterator _begin;
  1242     mutable Iterator _end;
  1346     mutable Iterator _end;
  1243     Functor _functor;
  1347     Functor _functor;
  1244   };
  1348   };
  1245 
  1349 
  1246   /// \brief Writable bool map for store each true assigned elements in 
  1350   /// \brief Writable bool map for logging each \c true assigned element in 
  1247   /// a back insertable container.
  1351   /// a back insertable container.
  1248   ///
  1352   ///
  1249   /// Writable bool map for store each true assigned elements in a back 
  1353   /// Writable bool map for logging each \c true assigned element by pushing
  1250   /// insertable container. It will push back all the keys set to true into
  1354   /// them into a back insertable container.
  1251   /// the container. It can be used to retrieve the items into a standard
  1355   /// It can be used to retrieve the items into a standard
  1252   /// container. The next example shows how can you store the undirected
  1356   /// container. The next example shows how you can store the
  1253   /// edges in a vector with prim algorithm.
  1357   /// edges found by the Prim algorithm in a vector.
  1254   ///
  1358   ///
  1255   ///\code
  1359   ///\code
  1256   /// vector<UEdge> span_tree_uedges;
  1360   /// vector<UEdge> span_tree_uedges;
  1257   /// BackInserterBoolMap<vector<UEdge> > inserter_map(span_tree_uedges);
  1361   /// BackInserterBoolMap<vector<UEdge> > inserter_map(span_tree_uedges);
  1258   /// prim(ugraph, cost, inserter_map);
  1362   /// prim(ugraph, cost, inserter_map);
  1259   ///\endcode
  1363   ///\endcode
       
  1364   ///
       
  1365   ///\sa StoreBoolMap
       
  1366   ///\sa FrontInserterBoolMap
       
  1367   ///\sa InserterBoolMap
  1260   template <typename Container,
  1368   template <typename Container,
  1261             typename Functor =
  1369             typename Functor =
  1262             _maps_bits::Identity<typename Container::value_type> >
  1370             _maps_bits::Identity<typename Container::value_type> >
  1263   class BackInserterBoolMap {
  1371   class BackInserterBoolMap {
  1264   public:
  1372   public:
  1265     typedef typename Container::value_type Key;
  1373     typedef typename Functor::argument_type Key;
  1266     typedef bool Value;
  1374     typedef bool Value;
  1267 
  1375 
  1268     /// Constructor
  1376     /// Constructor
  1269     BackInserterBoolMap(Container& _container, 
  1377     BackInserterBoolMap(Container& _container, 
  1270                         const Functor& _functor = Functor()) 
  1378                         const Functor& _functor = Functor()) 
  1271       : container(_container), functor(_functor) {}
  1379       : container(_container), functor(_functor) {}
  1272 
  1380 
  1273     /// Setter function of the map
  1381     /// The \c set function of the map
  1274     void set(const Key& key, Value value) {
  1382     void set(const Key& key, Value value) {
  1275       if (value) {
  1383       if (value) {
  1276 	container.push_back(functor(key));
  1384 	container.push_back(functor(key));
  1277       }
  1385       }
  1278     }
  1386     }
  1280   private:
  1388   private:
  1281     Container& container;
  1389     Container& container;
  1282     Functor functor;
  1390     Functor functor;
  1283   };
  1391   };
  1284 
  1392 
  1285   /// \brief Writable bool map for store each true assigned elements in 
  1393   /// \brief Writable bool map for logging each \c true assigned element in 
  1286   /// a front insertable container.
  1394   /// a front insertable container.
  1287   ///
  1395   ///
  1288   /// Writable bool map for store each true assigned elements in a front 
  1396   /// Writable bool map for logging each \c true assigned element by pushing
  1289   /// insertable container. It will push front all the keys set to \c true into
  1397   /// them into a front insertable container.
  1290   /// the container. For example see the BackInserterBoolMap.
  1398   /// It can be used to retrieve the items into a standard
       
  1399   /// container. For example see \ref BackInserterBoolMap.
       
  1400   ///
       
  1401   ///\sa BackInserterBoolMap
       
  1402   ///\sa InserterBoolMap
  1291   template <typename Container,
  1403   template <typename Container,
  1292             typename Functor =
  1404             typename Functor =
  1293             _maps_bits::Identity<typename Container::value_type> >
  1405             _maps_bits::Identity<typename Container::value_type> >
  1294   class FrontInserterBoolMap {
  1406   class FrontInserterBoolMap {
  1295   public:
  1407   public:
  1296     typedef typename Container::value_type Key;
  1408     typedef typename Functor::argument_type Key;
  1297     typedef bool Value;
  1409     typedef bool Value;
  1298 
  1410 
  1299     /// Constructor
  1411     /// Constructor
  1300     FrontInserterBoolMap(Container& _container,
  1412     FrontInserterBoolMap(Container& _container,
  1301                          const Functor& _functor = Functor()) 
  1413                          const Functor& _functor = Functor()) 
  1302       : container(_container), functor(_functor) {}
  1414       : container(_container), functor(_functor) {}
  1303 
  1415 
  1304     /// Setter function of the map
  1416     /// The \c set function of the map
  1305     void set(const Key& key, Value value) {
  1417     void set(const Key& key, Value value) {
  1306       if (value) {
  1418       if (value) {
  1307 	container.push_front(key);
  1419 	container.push_front(functor(key));
  1308       }
  1420       }
  1309     }
  1421     }
  1310     
  1422     
  1311   private:
  1423   private:
  1312     Container& container;    
  1424     Container& container;    
  1313     Functor functor;
  1425     Functor functor;
  1314   };
  1426   };
  1315 
  1427 
  1316   /// \brief Writable bool map for store each true assigned elements in 
  1428   /// \brief Writable bool map for storing each \c true assigned element in 
  1317   /// an insertable container.
  1429   /// an insertable container.
  1318   ///
  1430   ///
  1319   /// Writable bool map for store each true assigned elements in an 
  1431   /// Writable bool map for storing each \c true assigned element in an 
  1320   /// insertable container. It will insert all the keys set to \c true into
  1432   /// insertable container. It will insert all the keys set to \c true into
  1321   /// the container. If you want to store the cut edges of the strongly
  1433   /// the container.
       
  1434   ///
       
  1435   /// For example, if you want to store the cut arcs of the strongly
  1322   /// connected components in a set you can use the next code:
  1436   /// connected components in a set you can use the next code:
  1323   ///
  1437   ///
  1324   ///\code
  1438   ///\code
  1325   /// set<Edge> cut_edges;
  1439   /// set<Edge> cut_edges;
  1326   /// InserterBoolMap<set<Edge> > inserter_map(cut_edges);
  1440   /// InserterBoolMap<set<Edge> > inserter_map(cut_edges);
  1327   /// stronglyConnectedCutEdges(graph, cost, inserter_map);
  1441   /// stronglyConnectedCutEdges(graph, cost, inserter_map);
  1328   ///\endcode
  1442   ///\endcode
       
  1443   ///
       
  1444   ///\sa BackInserterBoolMap
       
  1445   ///\sa FrontInserterBoolMap
  1329   template <typename Container,
  1446   template <typename Container,
  1330             typename Functor =
  1447             typename Functor =
  1331             _maps_bits::Identity<typename Container::value_type> >
  1448             _maps_bits::Identity<typename Container::value_type> >
  1332   class InserterBoolMap {
  1449   class InserterBoolMap {
  1333   public:
  1450   public:
  1334     typedef typename Container::value_type Key;
  1451     typedef typename Container::value_type Key;
  1335     typedef bool Value;
  1452     typedef bool Value;
  1336 
  1453 
  1337     /// Constructor
  1454     /// Constructor with specified iterator
       
  1455     
       
  1456     /// Constructor with specified iterator.
       
  1457     /// \param _container The container for storing the elements.
       
  1458     /// \param _it The elements will be inserted before this iterator.
       
  1459     /// \param _functor The functor that is used when an element is stored.
  1338     InserterBoolMap(Container& _container, typename Container::iterator _it,
  1460     InserterBoolMap(Container& _container, typename Container::iterator _it,
  1339                     const Functor& _functor = Functor()) 
  1461                     const Functor& _functor = Functor()) 
  1340       : container(_container), it(_it), functor(_functor) {}
  1462       : container(_container), it(_it), functor(_functor) {}
  1341 
  1463 
  1342     /// Constructor
  1464     /// Constructor
       
  1465 
       
  1466     /// Constructor without specified iterator.
       
  1467     /// The elements will be inserted before <tt>_container.end()</tt>.
       
  1468     /// \param _container The container for storing the elements.
       
  1469     /// \param _functor The functor that is used when an element is stored.
  1343     InserterBoolMap(Container& _container, const Functor& _functor = Functor())
  1470     InserterBoolMap(Container& _container, const Functor& _functor = Functor())
  1344       : container(_container), it(_container.end()), functor(_functor) {}
  1471       : container(_container), it(_container.end()), functor(_functor) {}
  1345 
  1472 
  1346     /// Setter function of the map
  1473     /// The \c set function of the map
  1347     void set(const Key& key, Value value) {
  1474     void set(const Key& key, Value value) {
  1348       if (value) {
  1475       if (value) {
  1349 	it = container.insert(it, key);
  1476 	it = container.insert(it, functor(key));
  1350         ++it;
  1477         ++it;
  1351       }
  1478       }
  1352     }
  1479     }
  1353     
  1480     
  1354   private:
  1481   private:
  1355     Container& container;
  1482     Container& container;
  1356     typename Container::iterator it;
  1483     typename Container::iterator it;
  1357     Functor functor;
  1484     Functor functor;
  1358   };
  1485   };
  1359 
  1486 
  1360   /// \brief Fill the true set elements with a given value.
  1487   /// \brief Writable bool map for filling each \c true assigned element with a 
  1361   ///
  1488   /// given value.
  1362   /// Writable bool map to fill the elements set to \c true with a given value.
  1489   ///
  1363   /// The value can set 
  1490   /// Writable bool map for filling each \c true assigned element with a 
  1364   /// the container.
  1491   /// given value. The value can set the container.
  1365   ///
  1492   ///
  1366   /// The next code finds the connected components of the undirected graph
  1493   /// The following code finds the connected components of a graph
  1367   /// and stores it in the \c comp map:
  1494   /// and stores it in the \c comp map:
  1368   ///\code
  1495   ///\code
  1369   /// typedef UGraph::NodeMap<int> ComponentMap;
  1496   /// typedef UGraph::NodeMap<int> ComponentMap;
  1370   /// ComponentMap comp(ugraph);
  1497   /// ComponentMap comp(ugraph);
  1371   /// typedef FillBoolMap<UGraph::NodeMap<int> > ComponentFillerMap;
  1498   /// typedef FillBoolMap<UGraph::NodeMap<int> > ComponentFillerMap;
  1409     /// Sets the current fill value
  1536     /// Sets the current fill value
  1410     void fillValue(const typename Map::Value& _fill) {
  1537     void fillValue(const typename Map::Value& _fill) {
  1411       fill = _fill;
  1538       fill = _fill;
  1412     } 
  1539     } 
  1413 
  1540 
  1414     /// Setter function of the map
  1541     /// The \c set function of the map
  1415     void set(const Key& key, Value value) {
  1542     void set(const Key& key, Value value) {
  1416       if (value) {
  1543       if (value) {
  1417 	map.set(key, fill);
  1544 	map.set(key, fill);
  1418       }
  1545       }
  1419     }
  1546     }
  1422     Map& map;
  1549     Map& map;
  1423     typename Map::Value fill;
  1550     typename Map::Value fill;
  1424   };
  1551   };
  1425 
  1552 
  1426 
  1553 
  1427   /// \brief Writable bool map which stores for each true assigned elements  
  1554   /// \brief Writable bool map for storing the sequence number of 
  1428   /// the setting order number.
  1555   /// \c true assignments.  
  1429   ///
  1556   ///
  1430   /// Writable bool map which stores for each true assigned elements  
  1557   /// Writable bool map that stores for each \c true assigned elements  
  1431   /// the setting order number. It make easy to calculate the leaving
  1558   /// the sequence number of this setting.
       
  1559   /// It makes it easy to calculate the leaving
  1432   /// order of the nodes in the \c Dfs algorithm.
  1560   /// order of the nodes in the \c Dfs algorithm.
  1433   ///
  1561   ///
  1434   ///\code
  1562   ///\code
  1435   /// typedef Graph::NodeMap<int> OrderMap;
  1563   /// typedef Graph::NodeMap<int> OrderMap;
  1436   /// OrderMap order(graph);
  1564   /// OrderMap order(graph);
  1445   ///     dfs.start();
  1573   ///     dfs.start();
  1446   ///   }
  1574   ///   }
  1447   /// }
  1575   /// }
  1448   ///\endcode
  1576   ///\endcode
  1449   ///
  1577   ///
  1450   /// The discovering order can be stored a little harder because the
  1578   /// The storing of the discovering order is more difficult because the
  1451   /// ReachedMap should be readable in the dfs algorithm but the setting
  1579   /// ReachedMap should be readable in the dfs algorithm but the setting
  1452   /// order map is not readable. Now we should use the fork map:
  1580   /// order map is not readable. Thus we must use the fork map:
  1453   ///
  1581   ///
  1454   ///\code
  1582   ///\code
  1455   /// typedef Graph::NodeMap<int> OrderMap;
  1583   /// typedef Graph::NodeMap<int> OrderMap;
  1456   /// OrderMap order(graph);
  1584   /// OrderMap order(graph);
  1457   /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
  1585   /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
  1485     /// Number of set operations.
  1613     /// Number of set operations.
  1486     int num() const {
  1614     int num() const {
  1487       return counter;
  1615       return counter;
  1488     }
  1616     }
  1489 
  1617 
  1490     /// Setter function of the map
  1618     /// The \c set function of the map
  1491     void set(const Key& key, Value value) {
  1619     void set(const Key& key, Value value) {
  1492       if (value) {
  1620       if (value) {
  1493 	map.set(key, counter++);
  1621 	map.set(key, counter++);
  1494       }
  1622       }
  1495     }
  1623     }