lemon/maps.h
changeset 1713 49d22d34d95f
parent 1695 e6f99fe1723f
child 1725 22752dd6c693
equal deleted inserted replaced
13:bc2ce3903bee 14:7851c24d0a01
    36 
    36 
    37   /// Base class of maps.
    37   /// Base class of maps.
    38 
    38 
    39   /// Base class of maps.
    39   /// Base class of maps.
    40   /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    40   /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    41   template<typename K, typename T, typename _NeedCopy = False>
    41   template<typename K, typename T>
    42   class MapBase {
    42   class MapBase {
    43   public:
    43   public:
    44     /// \e
       
    45     typedef _NeedCopy NeedCopy;
       
    46     ///\e
    44     ///\e
    47     typedef K Key;
    45     typedef K Key;
    48     ///\e
    46     ///\e
    49     typedef T Value;
    47     typedef T Value;
    50   };
    48   };
    52   /// Null map. (a.k.a. DoNothingMap)
    50   /// Null map. (a.k.a. DoNothingMap)
    53 
    51 
    54   /// If you have to provide a map only for its type definitions,
    52   /// If you have to provide a map only for its type definitions,
    55   /// or if you have to provide a writable map, but
    53   /// or if you have to provide a writable map, but
    56   /// data written to it will sent to <tt>/dev/null</tt>...
    54   /// data written to it will sent to <tt>/dev/null</tt>...
    57   template<typename K, typename T, typename NC = False>
    55   template<typename K, typename T>
    58   class NullMap : public MapBase<K, T, NC> {
    56   class NullMap : public MapBase<K, T> {
    59   public:
    57   public:
    60     typedef MapBase<K, T, NC> Parent;
    58     typedef MapBase<K, T> Parent;
    61     typedef typename Parent::Key Key;
    59     typedef typename Parent::Key Key;
    62     typedef typename Parent::Value Value;
    60     typedef typename Parent::Value Value;
    63     
    61     
    64     /// Gives back a default constructed element.
    62     /// Gives back a default constructed element.
    65     T operator[](const K&) const { return T(); }
    63     T operator[](const K&) const { return T(); }
    66     /// Absorbs the value.
    64     /// Absorbs the value.
    67     void set(const K&, const T&) {}
    65     void set(const K&, const T&) {}
    68   };
    66   };
    69 
    67 
    70   template <typename K, typename V> 
    68   template <typename K, typename V> 
    71   NullMap<K, V, True> nullMap() {
    69   NullMap<K, V> nullMap() {
    72     return NullMap<K, V, True>();
    70     return NullMap<K, V>();
    73   }
    71   }
    74 
    72 
    75 
    73 
    76   /// Constant map.
    74   /// Constant map.
    77 
    75 
    78   /// This is a readable map which assigns a specified value to each key.
    76   /// This is a readable map which assigns a specified value to each key.
    79   /// In other aspects it is equivalent to the \ref NullMap.
    77   /// In other aspects it is equivalent to the \ref NullMap.
    80   /// \todo set could be used to set the value.
    78   /// \todo set could be used to set the value.
    81   template<typename K, typename T, typename NC = False>
    79   template<typename K, typename T>
    82   class ConstMap : public MapBase<K, T, NC> {
    80   class ConstMap : public MapBase<K, T> {
    83   private:
    81   private:
    84     T v;
    82     T v;
    85   public:
    83   public:
    86 
    84 
    87     typedef MapBase<K, T, NC> Parent;
    85     typedef MapBase<K, T> Parent;
    88     typedef typename Parent::Key Key;
    86     typedef typename Parent::Key Key;
    89     typedef typename Parent::Value Value;
    87     typedef typename Parent::Value Value;
    90 
    88 
    91     /// Default constructor
    89     /// Default constructor
    92 
    90 
   114   ///Returns a \ref ConstMap class
   112   ///Returns a \ref ConstMap class
   115 
   113 
   116   ///This function just returns a \ref ConstMap class.
   114   ///This function just returns a \ref ConstMap class.
   117   ///\relates ConstMap
   115   ///\relates ConstMap
   118   template<typename K, typename V> 
   116   template<typename K, typename V> 
   119   inline ConstMap<K, V, True> constMap(const V &v) {
   117   inline ConstMap<K, V> constMap(const V &v) {
   120     return ConstMap<K, V, True>(v);
   118     return ConstMap<K, V>(v);
   121   }
   119   }
   122 
   120 
   123 
   121 
   124   //\todo to document later
   122   //\todo to document later
   125   template<typename T, T v>
   123   template<typename T, T v>
   126   struct Const { };
   124   struct Const { };
   127 
   125 
   128   //\todo to document later
   126   //\todo to document later
   129   template<typename K, typename V, V v, typename NC>
   127   template<typename K, typename V, V v>
   130   class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
   128   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
   131   public:
   129   public:
   132     typedef MapBase<K, V, False> Parent;
   130     typedef MapBase<K, V> Parent;
   133     typedef typename Parent::Key Key;
   131     typedef typename Parent::Key Key;
   134     typedef typename Parent::Value Value;
   132     typedef typename Parent::Value Value;
   135 
   133 
   136     ConstMap() { }
   134     ConstMap() { }
   137     V operator[](const K&) const { return v; }
   135     V operator[](const K&) const { return v; }
   141   ///Returns a \ref ConstMap class
   139   ///Returns a \ref ConstMap class
   142 
   140 
   143   ///This function just returns a \ref ConstMap class.
   141   ///This function just returns a \ref ConstMap class.
   144   ///\relates ConstMap
   142   ///\relates ConstMap
   145   template<typename K, typename V, V v> 
   143   template<typename K, typename V, V v> 
   146   inline ConstMap<K, Const<V, v>, True> constMap() {
   144   inline ConstMap<K, Const<V, v> > constMap() {
   147     return ConstMap<K, Const<V, v>, True>();
   145     return ConstMap<K, Const<V, v> >();
   148   }
   146   }
   149 
   147 
   150   /// \c std::map wrapper
   148   /// \c std::map wrapper
   151 
   149 
   152   /// This is essentially a wrapper for \c std::map. With addition that
   150   /// This is essentially a wrapper for \c std::map. With addition that
   223 
   221 
   224   /// \brief Identity mapping.
   222   /// \brief Identity mapping.
   225   ///
   223   ///
   226   /// This mapping gives back the given key as value without any
   224   /// This mapping gives back the given key as value without any
   227   /// modification. 
   225   /// modification. 
   228   template <typename T, typename NC = False>
   226   template <typename T>
   229   class IdentityMap : public MapBase<T, T, NC> {
   227   class IdentityMap : public MapBase<T, T> {
   230   public:
   228   public:
   231     typedef MapBase<T, T, NC> Parent;
   229     typedef MapBase<T, T> Parent;
   232     typedef typename Parent::Key Key;
   230     typedef typename Parent::Key Key;
   233     typedef typename Parent::Value Value;
   231     typedef typename Parent::Value Value;
   234 
   232 
   235     const T& operator[](const T& t) const {
   233     const T& operator[](const T& t) const {
   236       return t;
   234       return t;
   240   ///Returns an \ref IdentityMap class
   238   ///Returns an \ref IdentityMap class
   241 
   239 
   242   ///This function just returns an \ref IdentityMap class.
   240   ///This function just returns an \ref IdentityMap class.
   243   ///\relates IdentityMap
   241   ///\relates IdentityMap
   244   template<typename T>
   242   template<typename T>
   245   inline IdentityMap<T, True> identityMap() {
   243   inline IdentityMap<T> identityMap() {
   246     return IdentityMap<T, True>();
   244     return IdentityMap<T>();
   247   }
   245   }
   248   
   246   
   249 
   247 
   250   ///Convert the \c Value of a map to another type.
   248   ///Convert the \c Value of a map to another type.
   251 
   249 
   252   ///This \ref concept::ReadMap "read only map"
   250   ///This \ref concept::ReadMap "read only map"
   253   ///converts the \c Value of a maps to type \c T.
   251   ///converts the \c Value of a maps to type \c T.
   254   ///Its \c Key is inherited from \c M.
   252   ///Its \c Key is inherited from \c M.
   255   template <typename M, typename T, typename NC = False> 
   253   template <typename M, typename T> 
   256   class ConvertMap : public MapBase<typename M::Key, T, NC> {
   254   class ConvertMap : public MapBase<typename M::Key, T> {
   257     typename SmartConstReference<M>::Type m;
   255     const M& m;
   258   public:
   256   public:
   259     typedef MapBase<typename M::Key, T, NC> Parent;
   257     typedef MapBase<typename M::Key, T> Parent;
   260     typedef typename Parent::Key Key;
   258     typedef typename Parent::Key Key;
   261     typedef typename Parent::Value Value;
   259     typedef typename Parent::Value Value;
   262 
   260 
   263     ///Constructor
   261     ///Constructor
   264 
   262 
   278 
   276 
   279   ///This function just returns an \ref ConvertMap class.
   277   ///This function just returns an \ref ConvertMap class.
   280   ///\relates ConvertMap
   278   ///\relates ConvertMap
   281   ///\todo The order of the template parameters are changed.
   279   ///\todo The order of the template parameters are changed.
   282   template<typename T, typename M>
   280   template<typename T, typename M>
   283   inline ConvertMap<M, T, True> convertMap(const M &m) {
   281   inline ConvertMap<M, T> convertMap(const M &m) {
   284     return ConvertMap<M, T, True>(m);
   282     return ConvertMap<M, T>(m);
   285   }
   283   }
   286 
   284 
   287   ///Sum of two maps
   285   ///Sum of two maps
   288 
   286 
   289   ///This \ref concept::ReadMap "read only map" returns the sum of the two
   287   ///This \ref concept::ReadMap "read only map" returns the sum of the two
   290   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   288   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   291   ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   289   ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
   292 
   290 
   293   template<typename M1, typename M2, typename NC = False> 
   291   template<typename M1, typename M2> 
   294   class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   292   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
   295     typename SmartConstReference<M1>::Type m1;
   293     const M1& m1;
   296     typename SmartConstReference<M2>::Type m2;
   294     const M2& m2;
   297 
   295 
   298   public:
   296   public:
   299     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   297     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   300     typedef typename Parent::Key Key;
   298     typedef typename Parent::Key Key;
   301     typedef typename Parent::Value Value;
   299     typedef typename Parent::Value Value;
   302 
   300 
   303     ///Constructor
   301     ///Constructor
   304     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   302     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   311   ///\todo How to call these type of functions?
   309   ///\todo How to call these type of functions?
   312   ///
   310   ///
   313   ///\relates AddMap
   311   ///\relates AddMap
   314   ///\todo Wrong scope in Doxygen when \c \\relates is used
   312   ///\todo Wrong scope in Doxygen when \c \\relates is used
   315   template<typename M1, typename M2> 
   313   template<typename M1, typename M2> 
   316   inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
   314   inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
   317     return AddMap<M1, M2, True>(m1,m2);
   315     return AddMap<M1, M2>(m1,m2);
   318   }
   316   }
   319 
   317 
   320   ///Shift a map with a constant.
   318   ///Shift a map with a constant.
   321 
   319 
   322   ///This \ref concept::ReadMap "read only map" returns the sum of the
   320   ///This \ref concept::ReadMap "read only map" returns the sum of the
   330   ///is equivalent with
   328   ///is equivalent with
   331   ///\code
   329   ///\code
   332   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   330   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   333   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
   331   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
   334   ///\endcode
   332   ///\endcode
   335   template<typename M, typename C = typename M::Value, typename NC = False> 
   333   template<typename M, typename C = typename M::Value> 
   336   class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
   334   class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
   337     typename SmartConstReference<M>::Type m;
   335     const M& m;
   338     C v;
   336     C v;
   339   public:
   337   public:
   340     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   338     typedef MapBase<typename M::Key, typename M::Value> Parent;
   341     typedef typename Parent::Key Key;
   339     typedef typename Parent::Key Key;
   342     typedef typename Parent::Value Value;
   340     typedef typename Parent::Value Value;
   343 
   341 
   344     ///Constructor
   342     ///Constructor
   345 
   343 
   354 
   352 
   355   ///This function just returns an \ref ShiftMap class.
   353   ///This function just returns an \ref ShiftMap class.
   356   ///\relates ShiftMap
   354   ///\relates ShiftMap
   357   ///\todo A better name is required.
   355   ///\todo A better name is required.
   358   template<typename M, typename C> 
   356   template<typename M, typename C> 
   359   inline ShiftMap<M, C, True> shiftMap(const M &m,const C &v) {
   357   inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
   360     return ShiftMap<M, C, True>(m,v);
   358     return ShiftMap<M, C>(m,v);
   361   }
   359   }
   362 
   360 
   363   ///Difference of two maps
   361   ///Difference of two maps
   364 
   362 
   365   ///This \ref concept::ReadMap "read only map" returns the difference
   363   ///This \ref concept::ReadMap "read only map" returns the difference
   366   ///of the values of the two
   364   ///of the values of the two
   367   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   365   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   368   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   366   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   369 
   367 
   370   template<typename M1, typename M2, typename NC = False> 
   368   template<typename M1, typename M2> 
   371   class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   369   class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
   372     typename SmartConstReference<M1>::Type m1;
   370     const M1& m1;
   373     typename SmartConstReference<M2>::Type m2;
   371     const M2& m2;
   374   public:
   372   public:
   375     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   373     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   376     typedef typename Parent::Key Key;
   374     typedef typename Parent::Key Key;
   377     typedef typename Parent::Value Value;
   375     typedef typename Parent::Value Value;
   378 
   376 
   379     ///Constructor
   377     ///Constructor
   380     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   378     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   385 
   383 
   386   ///This function just returns a \ref SubMap class.
   384   ///This function just returns a \ref SubMap class.
   387   ///
   385   ///
   388   ///\relates SubMap
   386   ///\relates SubMap
   389   template<typename M1, typename M2> 
   387   template<typename M1, typename M2> 
   390   inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
   388   inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
   391     return SubMap<M1, M2, True>(m1, m2);
   389     return SubMap<M1, M2>(m1, m2);
   392   }
   390   }
   393 
   391 
   394   ///Product of two maps
   392   ///Product of two maps
   395 
   393 
   396   ///This \ref concept::ReadMap "read only map" returns the product of the
   394   ///This \ref concept::ReadMap "read only map" returns the product of the
   397   ///values of the two
   395   ///values of the two
   398   ///given
   396   ///given
   399   ///maps. Its \c Key and \c Value will be inherited from \c M1.
   397   ///maps. Its \c Key and \c Value will be inherited from \c M1.
   400   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   398   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   401 
   399 
   402   template<typename M1, typename M2, typename NC = False> 
   400   template<typename M1, typename M2> 
   403   class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   401   class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
   404     typename SmartConstReference<M1>::Type m1;
   402     const M1& m1;
   405     typename SmartConstReference<M2>::Type m2;
   403     const M2& m2;
   406   public:
   404   public:
   407     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   405     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   408     typedef typename Parent::Key Key;
   406     typedef typename Parent::Key Key;
   409     typedef typename Parent::Value Value;
   407     typedef typename Parent::Value Value;
   410 
   408 
   411     ///Constructor
   409     ///Constructor
   412     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   410     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   416   ///Returns a \ref MulMap class
   414   ///Returns a \ref MulMap class
   417 
   415 
   418   ///This function just returns a \ref MulMap class.
   416   ///This function just returns a \ref MulMap class.
   419   ///\relates MulMap
   417   ///\relates MulMap
   420   template<typename M1, typename M2> 
   418   template<typename M1, typename M2> 
   421   inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
   419   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
   422     return MulMap<M1, M2, True>(m1,m2);
   420     return MulMap<M1, M2>(m1,m2);
   423   }
   421   }
   424  
   422  
   425   ///Scales a maps with a constant.
   423   ///Scales a maps with a constant.
   426 
   424 
   427   ///This \ref concept::ReadMap "read only map" returns the value of the
   425   ///This \ref concept::ReadMap "read only map" returns the value of the
   435   ///is equivalent with
   433   ///is equivalent with
   436   ///\code
   434   ///\code
   437   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   435   ///  ConstMap<X::Key, X::Value> c_tmp(v);
   438   ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
   436   ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
   439   ///\endcode
   437   ///\endcode
   440   template<typename M, typename C = typename M::Value, typename NC = False> 
   438   template<typename M, typename C = typename M::Value> 
   441   class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
   439   class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
   442     typename SmartConstReference<M>::Type m;
   440     const M& m;
   443     C v;
   441     C v;
   444   public:
   442   public:
   445     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   443     typedef MapBase<typename M::Key, typename M::Value> Parent;
   446     typedef typename Parent::Key Key;
   444     typedef typename Parent::Key Key;
   447     typedef typename Parent::Value Value;
   445     typedef typename Parent::Value Value;
   448 
   446 
   449     ///Constructor
   447     ///Constructor
   450 
   448 
   459 
   457 
   460   ///This function just returns an \ref ScaleMap class.
   458   ///This function just returns an \ref ScaleMap class.
   461   ///\relates ScaleMap
   459   ///\relates ScaleMap
   462   ///\todo A better name is required.
   460   ///\todo A better name is required.
   463   template<typename M, typename C> 
   461   template<typename M, typename C> 
   464   inline ScaleMap<M, C, True> scaleMap(const M &m,const C &v) {
   462   inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
   465     return ScaleMap<M, C, True>(m,v);
   463     return ScaleMap<M, C>(m,v);
   466   }
   464   }
   467 
   465 
   468   ///Quotient of two maps
   466   ///Quotient of two maps
   469 
   467 
   470   ///This \ref concept::ReadMap "read only map" returns the quotient of the
   468   ///This \ref concept::ReadMap "read only map" returns the quotient of the
   471   ///values of the two
   469   ///values of the two
   472   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   470   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   473   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   471   ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
   474 
   472 
   475   template<typename M1, typename M2, typename NC = False> 
   473   template<typename M1, typename M2> 
   476   class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   474   class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
   477     typename SmartConstReference<M1>::Type m1;
   475     const M1& m1;
   478     typename SmartConstReference<M2>::Type m2;
   476     const M2& m2;
   479   public:
   477   public:
   480     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   478     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   481     typedef typename Parent::Key Key;
   479     typedef typename Parent::Key Key;
   482     typedef typename Parent::Value Value;
   480     typedef typename Parent::Value Value;
   483 
   481 
   484     ///Constructor
   482     ///Constructor
   485     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   483     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   489   ///Returns a \ref DivMap class
   487   ///Returns a \ref DivMap class
   490 
   488 
   491   ///This function just returns a \ref DivMap class.
   489   ///This function just returns a \ref DivMap class.
   492   ///\relates DivMap
   490   ///\relates DivMap
   493   template<typename M1, typename M2> 
   491   template<typename M1, typename M2> 
   494   inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
   492   inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
   495     return DivMap<M1, M2, True>(m1,m2);
   493     return DivMap<M1, M2>(m1,m2);
   496   }
   494   }
   497   
   495   
   498   ///Composition of two maps
   496   ///Composition of two maps
   499 
   497 
   500   ///This \ref concept::ReadMap "read only map" returns the composition of
   498   ///This \ref concept::ReadMap "read only map" returns the composition of
   510   ///Its \c Key is inherited from \c M2 and its \c Value is from
   508   ///Its \c Key is inherited from \c M2 and its \c Value is from
   511   ///\c M1.
   509   ///\c M1.
   512   ///The \c M2::Value must be convertible to \c M1::Key.
   510   ///The \c M2::Value must be convertible to \c M1::Key.
   513   ///\todo Check the requirements.
   511   ///\todo Check the requirements.
   514 
   512 
   515   template <typename M1, typename M2, typename NC = False> 
   513   template <typename M1, typename M2> 
   516   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
   514   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
   517     typename SmartConstReference<M1>::Type m1;
   515     const M1& m1;
   518     typename SmartConstReference<M2>::Type m2;
   516     const M2& m2;
   519   public:
   517   public:
   520     typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
   518     typedef MapBase<typename M2::Key, typename M1::Value> Parent;
   521     typedef typename Parent::Key Key;
   519     typedef typename Parent::Key Key;
   522     typedef typename Parent::Value Value;
   520     typedef typename Parent::Value Value;
   523 
   521 
   524     ///Constructor
   522     ///Constructor
   525     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   523     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   529 
   527 
   530   ///This function just returns a \ref ComposeMap class.
   528   ///This function just returns a \ref ComposeMap class.
   531   ///
   529   ///
   532   ///\relates ComposeMap
   530   ///\relates ComposeMap
   533   template <typename M1, typename M2> 
   531   template <typename M1, typename M2> 
   534   inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
   532   inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
   535     return ComposeMap<M1, M2, True>(m1,m2);
   533     return ComposeMap<M1, M2>(m1,m2);
   536   }
   534   }
   537   
   535   
   538   ///Combines of two maps using an STL (binary) functor.
   536   ///Combines of two maps using an STL (binary) functor.
   539 
   537 
   540   ///Combines of two maps using an STL (binary) functor.
   538   ///Combines of two maps using an STL (binary) functor.
   559   ///\todo Check the requirements.
   557   ///\todo Check the requirements.
   560 
   558 
   561   template<typename M1, typename M2, typename F,
   559   template<typename M1, typename M2, typename F,
   562 	   typename V = typename F::result_type,
   560 	   typename V = typename F::result_type,
   563 	   typename NC = False> 
   561 	   typename NC = False> 
   564   class CombineMap : public MapBase<typename M1::Key, V, NC> {
   562   class CombineMap : public MapBase<typename M1::Key, V> {
   565     typename SmartConstReference<M1>::Type m1;
   563     const M1& m1;
   566     typename SmartConstReference<M2>::Type m2;
   564     const M2& m2;
   567     F f;
   565     F f;
   568   public:
   566   public:
   569     typedef MapBase<typename M1::Key, V, NC> Parent;
   567     typedef MapBase<typename M1::Key, V> Parent;
   570     typedef typename Parent::Key Key;
   568     typedef typename Parent::Key Key;
   571     typedef typename Parent::Value Value;
   569     typedef typename Parent::Value Value;
   572 
   570 
   573     ///Constructor
   571     ///Constructor
   574     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   572     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   591   ///addMap(m1,m2)
   589   ///addMap(m1,m2)
   592   ///\endcode
   590   ///\endcode
   593   ///
   591   ///
   594   ///\relates CombineMap
   592   ///\relates CombineMap
   595   template<typename M1, typename M2, typename F, typename V> 
   593   template<typename M1, typename M2, typename F, typename V> 
   596   inline CombineMap<M1, M2, F, V, True> 
   594   inline CombineMap<M1, M2, F, V> 
   597   combineMap(const M1& m1,const M2& m2, const F& f) {
   595   combineMap(const M1& m1,const M2& m2, const F& f) {
   598     return CombineMap<M1, M2, F, V, True>(m1,m2,f);
   596     return CombineMap<M1, M2, F, V>(m1,m2,f);
   599   }
   597   }
   600 
   598 
   601   template<typename M1, typename M2, typename F> 
   599   template<typename M1, typename M2, typename F> 
   602   inline CombineMap<M1, M2, F, typename F::result_type, True> 
   600   inline CombineMap<M1, M2, F, typename F::result_type> 
   603   combineMap(const M1& m1, const M2& m2, const F& f) {
   601   combineMap(const M1& m1, const M2& m2, const F& f) {
   604     return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
   602     return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
   605   }
   603   }
   606 
   604 
   607   template<typename M1, typename M2, typename K1, typename K2, typename V> 
   605   template<typename M1, typename M2, typename K1, typename K2, typename V> 
   608   inline CombineMap<M1, M2, V (*)(K1, K2), V, True> 
   606   inline CombineMap<M1, M2, V (*)(K1, K2), V> 
   609   combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
   607   combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
   610     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   608     return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
   611   }
   609   }
   612 
   610 
   613   ///Negative value of a map
   611   ///Negative value of a map
   616   ///value of the
   614   ///value of the
   617   ///value returned by the
   615   ///value returned by the
   618   ///given map. Its \c Key and \c Value will be inherited from \c M.
   616   ///given map. Its \c Key and \c Value will be inherited from \c M.
   619   ///The unary \c - operator must be defined for \c Value, of course.
   617   ///The unary \c - operator must be defined for \c Value, of course.
   620 
   618 
   621   template<typename M, typename NC = False> 
   619   template<typename M> 
   622   class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
   620   class NegMap : public MapBase<typename M::Key, typename M::Value> {
   623     typename SmartConstReference<M>::Type m;
   621     const M& m;
   624   public:
   622   public:
   625     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   623     typedef MapBase<typename M::Key, typename M::Value> Parent;
   626     typedef typename Parent::Key Key;
   624     typedef typename Parent::Key Key;
   627     typedef typename Parent::Value Value;
   625     typedef typename Parent::Value Value;
   628 
   626 
   629     ///Constructor
   627     ///Constructor
   630     NegMap(const M &_m) : m(_m) {};
   628     NegMap(const M &_m) : m(_m) {};
   634   ///Returns a \ref NegMap class
   632   ///Returns a \ref NegMap class
   635 
   633 
   636   ///This function just returns a \ref NegMap class.
   634   ///This function just returns a \ref NegMap class.
   637   ///\relates NegMap
   635   ///\relates NegMap
   638   template <typename M> 
   636   template <typename M> 
   639   inline NegMap<M, True> negMap(const M &m) {
   637   inline NegMap<M> negMap(const M &m) {
   640     return NegMap<M, True>(m);
   638     return NegMap<M>(m);
   641   }
   639   }
   642 
   640 
   643 
   641 
   644   ///Absolute value of a map
   642   ///Absolute value of a map
   645 
   643 
   662   ///  template<> inline double t_abs<>(double n) {return fabs(n);}
   660   ///  template<> inline double t_abs<>(double n) {return fabs(n);}
   663   ///  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
   661   ///  template<> inline long double t_abs<>(long double n) {return fabsl(n);}
   664   ///\endcode
   662   ///\endcode
   665   
   663   
   666 
   664 
   667   template<typename M, typename NC = False> 
   665   template<typename M> 
   668   class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
   666   class AbsMap : public MapBase<typename M::Key, typename M::Value> {
   669     typename SmartConstReference<M>::Type m;
   667     const M& m;
   670   public:
   668   public:
   671     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   669     typedef MapBase<typename M::Key, typename M::Value> Parent;
   672     typedef typename Parent::Key Key;
   670     typedef typename Parent::Key Key;
   673     typedef typename Parent::Value Value;
   671     typedef typename Parent::Value Value;
   674 
   672 
   675     ///Constructor
   673     ///Constructor
   676     AbsMap(const M &_m) : m(_m) {};
   674     AbsMap(const M &_m) : m(_m) {};
   684   ///Returns a \ref AbsMap class
   682   ///Returns a \ref AbsMap class
   685 
   683 
   686   ///This function just returns a \ref AbsMap class.
   684   ///This function just returns a \ref AbsMap class.
   687   ///\relates AbsMap
   685   ///\relates AbsMap
   688   template<typename M> 
   686   template<typename M> 
   689   inline AbsMap<M, True> absMap(const M &m) {
   687   inline AbsMap<M> absMap(const M &m) {
   690     return AbsMap<M, True>(m);
   688     return AbsMap<M>(m);
   691   }
   689   }
   692 
   690 
   693   ///Converts an STL style functor to a map
   691   ///Converts an STL style functor to a map
   694 
   692 
   695   ///This \ref concept::ReadMap "read only map" returns the value
   693   ///This \ref concept::ReadMap "read only map" returns the value
   705 
   703 
   706   template<typename F, 
   704   template<typename F, 
   707 	   typename K = typename F::argument_type, 
   705 	   typename K = typename F::argument_type, 
   708 	   typename V = typename F::result_type,
   706 	   typename V = typename F::result_type,
   709 	   typename NC = False> 
   707 	   typename NC = False> 
   710   class FunctorMap : public MapBase<K, V, NC> {
   708   class FunctorMap : public MapBase<K, V> {
   711     F f;
   709     F f;
   712   public:
   710   public:
   713     typedef MapBase<K, V, NC> Parent;
   711     typedef MapBase<K, V> Parent;
   714     typedef typename Parent::Key Key;
   712     typedef typename Parent::Key Key;
   715     typedef typename Parent::Value Value;
   713     typedef typename Parent::Value Value;
   716 
   714 
   717     ///Constructor
   715     ///Constructor
   718     FunctorMap(const F &_f) : f(_f) {}
   716     FunctorMap(const F &_f) : f(_f) {}
   725   ///This function just returns a \ref FunctorMap class.
   723   ///This function just returns a \ref FunctorMap class.
   726   ///
   724   ///
   727   ///The third template parameter isn't necessary to be given.
   725   ///The third template parameter isn't necessary to be given.
   728   ///\relates FunctorMap
   726   ///\relates FunctorMap
   729   template<typename K, typename V, typename F> inline 
   727   template<typename K, typename V, typename F> inline 
   730   FunctorMap<F, K, V, True> functorMap(const F &f) {
   728   FunctorMap<F, K, V> functorMap(const F &f) {
   731     return FunctorMap<F, K, V, True>(f);
   729     return FunctorMap<F, K, V>(f);
   732   }
   730   }
   733 
   731 
   734   template <typename F> inline 
   732   template <typename F> inline 
   735   FunctorMap<F, typename F::argument_type, typename F::result_type, True> 
   733   FunctorMap<F, typename F::argument_type, typename F::result_type> 
   736   functorMap(const F &f) {
   734   functorMap(const F &f) {
   737     return FunctorMap<F, typename F::argument_type, 
   735     return FunctorMap<F, typename F::argument_type, 
   738       typename F::result_type, True>(f);
   736       typename F::result_type>(f);
   739   }
   737   }
   740 
   738 
   741   template <typename K, typename V> inline 
   739   template <typename K, typename V> inline 
   742   FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
   740   FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
   743     return FunctorMap<V (*)(K), K, V, True>(f);
   741     return FunctorMap<V (*)(K), K, V>(f);
   744   }
   742   }
   745 
   743 
   746 
   744 
   747   ///Converts a map to an STL style (unary) functor
   745   ///Converts a map to an STL style (unary) functor
   748 
   746 
   751   ///
   749   ///
   752   ///For the sake of convenience it also works as
   750   ///For the sake of convenience it also works as
   753   ///a ususal \ref concept::ReadMap "readable map",
   751   ///a ususal \ref concept::ReadMap "readable map",
   754   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
   752   ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
   755 
   753 
   756   template <typename M, typename NC = False> 
   754   template <typename M> 
   757   class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
   755   class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
   758     typename SmartConstReference<M>::Type m;
   756     const M& m;
   759   public:
   757   public:
   760     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
   758     typedef MapBase<typename M::Key, typename M::Value> Parent;
   761     typedef typename Parent::Key Key;
   759     typedef typename Parent::Key Key;
   762     typedef typename Parent::Value Value;
   760     typedef typename Parent::Value Value;
   763 
   761 
   764     ///\e
   762     ///\e
   765     typedef typename M::Key argument_type;
   763     typedef typename M::Key argument_type;
   777   ///Returns a \ref MapFunctor class
   775   ///Returns a \ref MapFunctor class
   778 
   776 
   779   ///This function just returns a \ref MapFunctor class.
   777   ///This function just returns a \ref MapFunctor class.
   780   ///\relates MapFunctor
   778   ///\relates MapFunctor
   781   template<typename M> 
   779   template<typename M> 
   782   inline MapFunctor<M, True> mapFunctor(const M &m) {
   780   inline MapFunctor<M> mapFunctor(const M &m) {
   783     return MapFunctor<M, True>(m);
   781     return MapFunctor<M>(m);
   784   }
   782   }
   785 
   783 
   786 
   784 
   787   ///Applies all map setting operations to two maps
   785   ///Applies all map setting operations to two maps
   788 
   786 
   793   ///corresponding values of \c M1.
   791   ///corresponding values of \c M1.
   794   ///
   792   ///
   795   ///The \c Key and \c Value will be inherited from \c M1.
   793   ///The \c Key and \c Value will be inherited from \c M1.
   796   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   794   ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
   797 
   795 
   798   template<typename  M1, typename M2, typename NC = False> 
   796   template<typename  M1, typename M2> 
   799   class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
   797   class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
   800     typename SmartConstReference<M1>::Type m1;
   798     const M1& m1;
   801     typename SmartConstReference<M2>::Type m2;
   799     const M2& m2;
   802   public:
   800   public:
   803     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
   801     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   804     typedef typename Parent::Key Key;
   802     typedef typename Parent::Key Key;
   805     typedef typename Parent::Value Value;
   803     typedef typename Parent::Value Value;
   806 
   804 
   807     ///Constructor
   805     ///Constructor
   808     ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   806     ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   816   ///\todo How to call these type of functions?
   814   ///\todo How to call these type of functions?
   817   ///
   815   ///
   818   ///\relates ForkMap
   816   ///\relates ForkMap
   819   ///\todo Wrong scope in Doxygen when \c \\relates is used
   817   ///\todo Wrong scope in Doxygen when \c \\relates is used
   820   template <typename M1, typename M2> 
   818   template <typename M1, typename M2> 
   821   inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
   819   inline ForkMap<M1, M2> forkMap(const M1 &m1,const M2 &m2) {
   822     return ForkMap<M1, M2, True>(m1,m2);
   820     return ForkMap<M1, M2>(m1,m2);
   823   }
   821   }
   824 
   822 
   825 
   823 
   826   
   824   
   827   /* ************* BOOL MAPS ******************* */
   825   /* ************* BOOL MAPS ******************* */
   832   ///logical negation of
   830   ///logical negation of
   833   ///value returned by the
   831   ///value returned by the
   834   ///given map. Its \c Key and will be inherited from \c M,
   832   ///given map. Its \c Key and will be inherited from \c M,
   835   ///its Value is <tt>bool</tt>.
   833   ///its Value is <tt>bool</tt>.
   836 
   834 
   837   template <typename M, typename NC = False> 
   835   template <typename M> 
   838   class NotMap : public MapBase<typename M::Key, bool, NC> {
   836   class NotMap : public MapBase<typename M::Key, bool> {
   839     typename SmartConstReference<M>::Type m;
   837     const M& m;
   840   public:
   838   public:
   841     typedef MapBase<typename M::Key, bool, NC> Parent;
   839     typedef MapBase<typename M::Key, bool> Parent;
   842     typedef typename Parent::Key Key;
   840     typedef typename Parent::Key Key;
   843     typedef typename Parent::Value Value;
   841     typedef typename Parent::Value Value;
   844 
   842 
   845     ///Constructor
   843     ///Constructor
   846     NotMap(const M &_m) : m(_m) {};
   844     NotMap(const M &_m) : m(_m) {};
   850   ///Returns a \ref NotMap class
   848   ///Returns a \ref NotMap class
   851   
   849   
   852   ///This function just returns a \ref NotMap class.
   850   ///This function just returns a \ref NotMap class.
   853   ///\relates NotMap
   851   ///\relates NotMap
   854   template <typename M> 
   852   template <typename M> 
   855   inline NotMap<M, True> notMap(const M &m) {
   853   inline NotMap<M> notMap(const M &m) {
   856     return NotMap<M, True>(m);
   854     return NotMap<M>(m);
   857   }
   855   }
   858 
   856 
   859   /// @}
   857   /// @}
   860 }
   858 }
   861 
   859