COIN-OR::LEMON - Graph Library

Changeset 1675:fa89ffb27a6d in lemon-0.x


Ignore:
Timestamp:
09/08/05 16:34:50 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2193
Message:

Redesign of the map adaptors.
/smart reference handling only used by functions/

Better handling of the function objects and functions.


\todo May we use operators instead of the addMap, subMap...?

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/maps.h

    r1669 r1675  
    4040  /// Base class of maps.
    4141  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    42   template<typename K, typename T>
    43   class MapBase
    44   {
    45   public:
     42  template<typename K, typename T, typename _NeedCopy = False>
     43  class MapBase {
     44  public:
     45    /// \e
     46    typedef _NeedCopy NeedCopy;
    4647    ///\e
    4748    typedef K Key;
     
    5556  /// or if you have to provide a writable map, but
    5657  /// data written to it will sent to <tt>/dev/null</tt>...
    57   template<typename K, typename T>
    58   class NullMap : public MapBase<K,T>
    59   {
    60   public:
     58  template<typename K, typename T, typename NC = False>
     59  class NullMap : public MapBase<K, T, NC> {
     60  public:
     61    typedef MapBase<K, T, NC> Parent;
     62    typedef typename Parent::Key Key;
     63    typedef typename Parent::Value Value;
    6164   
    62     typedef True NeedCopy;
    63 
    6465    /// Gives back a default constructed element.
    6566    T operator[](const K&) const { return T(); }
     
    6970
    7071  template <typename K, typename V>
    71   NullMap<K, V> nullMap() {
    72     return NullMap<K, V>();
     72  NullMap<K, V, True> nullMap() {
     73    return NullMap<K, V, True>();
    7374  }
    7475
     
    7980  /// In other aspects it is equivalent to the \ref NullMap.
    8081  /// \todo set could be used to set the value.
    81   template<typename K, typename T>
    82   class ConstMap : public MapBase<K,T>
    83   {
     82  template<typename K, typename T, typename NC = False>
     83  class ConstMap : public MapBase<K, T, NC> {
     84  private:
    8485    T v;
    8586  public:
    8687
    87     typedef True NeedCopy;
     88    typedef MapBase<K, T, NC> Parent;
     89    typedef typename Parent::Key Key;
     90    typedef typename Parent::Value Value;
    8891
    8992    /// Default constructor
     
    103106    template<typename T1>
    104107    struct rebind {
    105       typedef ConstMap<K,T1> other;
     108      typedef ConstMap<K, T1> other;
    106109    };
    107110
    108111    template<typename T1>
    109     ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
     112    ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
    110113  };
    111114
     
    114117  ///This function just returns a \ref ConstMap class.
    115118  ///\relates ConstMap
    116   template<class K,class V>
    117   inline ConstMap<K,V> constMap(const V &v)
    118   {
    119     return ConstMap<K,V>(v);
     119  template<typename K, typename V>
     120  inline ConstMap<K, V, True> constMap(const V &v) {
     121    return ConstMap<K, V, True>(v);
    120122  }
    121123
     
    124126  template<typename T, T v>
    125127  struct Const { };
     128
    126129  //\todo to document later
    127   template<typename K, typename V, V v>
    128   class ConstMap<K, Const<V, v> > : public MapBase<K, V>
    129   {
    130   public:
     130  template<typename K, typename V, V v, typename NC>
     131  class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
     132  public:
     133    typedef MapBase<K, V, False> Parent;
     134    typedef typename Parent::Key Key;
     135    typedef typename Parent::Value Value;
     136
    131137    ConstMap() { }
    132138    V operator[](const K&) const { return v; }
     
    134140  };
    135141
     142  ///Returns a \ref ConstMap class
     143
     144  ///This function just returns a \ref ConstMap class.
     145  ///\relates ConstMap
     146  template<typename K, typename V, V v>
     147  inline ConstMap<K, Const<V, v>, True> constMap() {
     148    return ConstMap<K, Const<V, v>, True>();
     149  }
     150
    136151  /// \c std::map wrapper
    137152
     
    141156  /// \todo Provide allocator parameter...
    142157  template <typename K, typename T, typename Compare = std::less<K> >
    143   class StdMap : public std::map<K,T,Compare> {
    144     typedef std::map<K,T,Compare> parent;
     158  class StdMap : public std::map<K, T, Compare> {
     159    typedef std::map<K, T, Compare> parent;
    145160    T v;
    146161    typedef typename parent::value_type PairType;
     
    172187   
    173188    template<typename T1, typename Comp1>
    174     StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) {
     189    StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) {
    175190      //FIXME;
    176191    }
     
    179194      return insert(PairType(k,v)).first -> second;
    180195    }
     196
    181197    ConstReference operator[](const Key &k) const {
    182198      typename parent::iterator i = lower_bound(k);
     
    198214    template<typename T1>
    199215    struct rebind {
    200       typedef StdMap<Key,T1,Compare> other;
     216      typedef StdMap<Key, T1,Compare> other;
    201217    };
    202218  };
     
    211227  /// This mapping gives back the given key as value without any
    212228  /// modification.
    213   template <typename T>
    214   class IdentityMap {
    215   public:
    216     typedef T Key;
    217     typedef T Value;
    218 
    219     const Value& operator[](const Key& t) const {
     229  template <typename T, typename NC = False>
     230  class IdentityMap : public MapBase<T, T, NC> {
     231  public:
     232    typedef MapBase<T, T, NC> Parent;
     233    typedef typename Parent::Key Key;
     234    typedef typename Parent::Value Value;
     235
     236    const T& operator[](const T& t) const {
    220237      return t;
    221238    }
    222239  };
     240
     241  ///Returns an \ref IdentityMap class
     242
     243  ///This function just returns an \ref IdentityMap class.
     244  ///\relates IdentityMap
     245  template<typename T>
     246  inline IdentityMap<T, True> identityMap() {
     247    return IdentityMap<T, True>();
     248  }
     249 
    223250
    224251  ///Convert the \c Value of a map to another type.
     
    227254  ///converts the \c Value of a maps to type \c T.
    228255  ///Its \c Key is inherited from \c M.
    229   template<class M, class T>
    230   class ConvertMap {
     256  template <typename M, typename T, typename NC = False>
     257  class ConvertMap : public MapBase<typename M::Key, T, NC> {
    231258    typename SmartConstReference<M>::Type m;
    232259  public:
    233 
    234     typedef True NeedCopy;
    235 
    236     ///\e
    237     typedef typename M::Key Key;
    238     ///\e
    239     typedef T Value;
     260    typedef MapBase<typename M::Key, T, NC> Parent;
     261    typedef typename Parent::Key Key;
     262    typedef typename Parent::Value Value;
    240263
    241264    ///Constructor
     
    250273    /// \param k The key
    251274    /// \return The target of the edge
    252     Value operator[](Key k) const {return m[k];}
     275    Value operator[](const Key& k) const {return m[k];}
    253276  };
    254277 
     
    258281  ///\relates ConvertMap
    259282  ///\todo The order of the template parameters are changed.
    260   template<class T, class M>
    261   inline ConvertMap<M,T> convertMap(const M &m)
    262   {
    263     return ConvertMap<M,T>(m);
     283  template<typename T, typename M>
     284  inline ConvertMap<M, T, True> convertMap(const M &m) {
     285    return ConvertMap<M, T, True>(m);
    264286  }
    265287
     
    270292  ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
    271293
    272   template<class M1,class M2>
    273   class AddMap
    274   {
     294  template<typename M1, typename M2, typename NC = False>
     295  class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    275296    typename SmartConstReference<M1>::Type m1;
    276297    typename SmartConstReference<M2>::Type m2;
    277298
    278299  public:
    279 
    280     typedef True NeedCopy;
    281 
    282     ///\e
    283     typedef typename M1::Key Key;
    284     ///\e
    285     typedef typename M1::Value Value;
     300    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     301    typedef typename Parent::Key Key;
     302    typedef typename Parent::Value Value;
    286303
    287304    ///Constructor
     
    297314  ///\relates AddMap
    298315  ///\todo Wrong scope in Doxygen when \c \\relates is used
    299   template<class M1,class M2>
    300   inline AddMap<M1,M2> addMap(const M1 &m1,const M2 &m2)
    301   {
    302     return AddMap<M1,M2>(m1,m2);
     316  template<typename M1, typename M2>
     317  inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
     318    return AddMap<M1, M2, True>(m1,m2);
    303319  }
    304320
     
    318334  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
    319335  ///\endcode
    320   template<class M>
    321   class ShiftMap
    322   {
     336  template<typename M, typename NC = False>
     337  class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
    323338    typename SmartConstReference<M>::Type m;
    324339    typename M::Value v;
    325340  public:
    326 
    327     typedef True NeedCopy;
    328     ///\e
    329     typedef typename M::Key Key;
    330     ///\e
    331     typedef typename M::Value Value;
     341    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     342    typedef typename Parent::Key Key;
     343    typedef typename Parent::Value Value;
    332344
    333345    ///Constructor
     
    336348    ///\param _m is the undelying map
    337349    ///\param _v is the shift value
    338     ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
     350    ShiftMap(const M &_m, const Value &_v ) : m(_m), v(_v) {};
    339351    Value operator[](Key k) const {return m[k]+v;}
    340352  };
     
    345357  ///\relates ShiftMap
    346358  ///\todo A better name is required.
    347   template<class M>
    348   inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v)
    349   {
    350     return ShiftMap<M>(m,v);
     359  template<typename M>
     360  inline ShiftMap<M, True> shiftMap(const M &m,const typename M::Value &v) {
     361    return ShiftMap<M, True>(m,v);
    351362  }
    352363
     
    358369  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    359370
    360   template<class M1,class M2>
    361   class SubMap
    362   {
     371  template<typename M1, typename M2, typename NC = False>
     372  class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    363373    typename SmartConstReference<M1>::Type m1;
    364374    typename SmartConstReference<M2>::Type m2;
    365375  public:
    366 
    367     typedef True NeedCopy;
    368     ///\e
    369     typedef typename M1::Key Key;
    370     ///\e
    371     typedef typename M1::Value Value;
     376    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     377    typedef typename Parent::Key Key;
     378    typedef typename Parent::Value Value;
    372379
    373380    ///Constructor
     
    381388  ///
    382389  ///\relates SubMap
    383   template<class M1,class M2>
    384   inline SubMap<M1,M2> subMap(const M1 &m1,const M2 &m2)
    385   {
    386     return SubMap<M1,M2>(m1,m2);
     390  template<typename M1, typename M2>
     391  inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
     392    return SubMap<M1, M2, True>(m1, m2);
    387393  }
    388394
     
    395401  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    396402
    397   template<class M1,class M2>
    398   class MulMap
    399   {
     403  template<typename M1, typename M2, typename NC = False>
     404  class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    400405    typename SmartConstReference<M1>::Type m1;
    401406    typename SmartConstReference<M2>::Type m2;
    402407  public:
    403 
    404     typedef True NeedCopy;
    405     ///\e
    406     typedef typename M1::Key Key;
    407     ///\e
    408     typedef typename M1::Value Value;
     408    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     409    typedef typename Parent::Key Key;
     410    typedef typename Parent::Value Value;
    409411
    410412    ///Constructor
     
    417419  ///This function just returns a \ref MulMap class.
    418420  ///\relates MulMap
    419   template<class M1,class M2>
    420   inline MulMap<M1,M2> mulMap(const M1 &m1,const M2 &m2)
    421   {
    422     return MulMap<M1,M2>(m1,m2);
     421  template<typename M1, typename M2>
     422  inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
     423    return MulMap<M1, M2, True>(m1,m2);
    423424  }
    424425 
     
    438439  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
    439440  ///\endcode
    440   template<class M>
    441   class ScaleMap
    442   {
     441  template<typename M, typename NC = False>
     442  class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
    443443    typename SmartConstReference<M>::Type m;
    444444    typename M::Value v;
    445445  public:
    446 
    447     typedef True NeedCopy;
    448     ///\e
    449     typedef typename M::Key Key;
    450     ///\e
    451     typedef typename M::Value Value;
     446    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     447    typedef typename Parent::Key Key;
     448    typedef typename Parent::Value Value;
    452449
    453450    ///Constructor
     
    465462  ///\relates ScaleMap
    466463  ///\todo A better name is required.
    467   template<class M>
    468   inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v)
    469   {
    470     return ScaleMap<M>(m,v);
     464  template<typename M>
     465  inline ScaleMap<M, True> scaleMap(const M &m,const typename M::Value &v) {
     466    return ScaleMap<M, True>(m,v);
    471467  }
    472468
     
    478474  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    479475
    480   template<class M1,class M2>
    481   class DivMap
    482   {
     476  template<typename M1, typename M2, typename NC = False>
     477  class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    483478    typename SmartConstReference<M1>::Type m1;
    484479    typename SmartConstReference<M2>::Type m2;
    485480  public:
    486 
    487     typedef True NeedCopy;
    488     ///\e
    489     typedef typename M1::Key Key;
    490     ///\e
    491     typedef typename M1::Value Value;
     481    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     482    typedef typename Parent::Key Key;
     483    typedef typename Parent::Value Value;
    492484
    493485    ///Constructor
     
    500492  ///This function just returns a \ref DivMap class.
    501493  ///\relates DivMap
    502   template<class M1,class M2>
    503   inline DivMap<M1,M2> divMap(const M1 &m1,const M2 &m2)
    504   {
    505     return DivMap<M1,M2>(m1,m2);
     494  template<typename M1, typename M2>
     495  inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
     496    return DivMap<M1, M2, True>(m1,m2);
    506497  }
    507498 
     
    514505  ///then for
    515506  ///\code
    516   ///  ComposeMap<M1,M2> cm(m1,m2);
     507  ///  ComposeMap<M1, M2> cm(m1,m2);
    517508  ///\endcode
    518509  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
     
    523514  ///\todo Check the requirements.
    524515
    525   template<class M1,class M2>
    526   class ComposeMap
    527   {
     516  template <typename M1, typename M2, typename NC = False>
     517  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
    528518    typename SmartConstReference<M1>::Type m1;
    529519    typename SmartConstReference<M2>::Type m2;
    530520  public:
    531 
    532     typedef True NeedCopy;
    533     ///\e
    534     typedef typename M2::Key Key;
    535     ///\e
    536     typedef typename M1::Value Value;
     521    typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
     522    typedef typename Parent::Key Key;
     523    typedef typename Parent::Value Value;
    537524
    538525    ///Constructor
     
    545532  ///
    546533  ///\relates ComposeMap
    547   template<class M1,class M2>
    548   inline ComposeMap<M1,M2> composeMap(const M1 &m1,const M2 &m2)
    549   {
    550     return ComposeMap<M1,M2>(m1,m2);
     534  template <typename M1, typename M2>
     535  inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
     536    return ComposeMap<M1, M2, True>(m1,m2);
    551537  }
    552538 
     
    564550  ///then for
    565551  ///\code
    566   ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
     552  ///  CombineMap<M1, M2,F,V> cm(m1,m2,f);
    567553  ///\endcode
    568554  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
     
    574560  ///\todo Check the requirements.
    575561
    576   template<class M1,class M2,class F,class V = typename F::result_type>
    577   class CombineMap
    578   {
     562  template<typename M1, typename M2, typename F,
     563           typename V = typename F::result_type,
     564           typename NC = False>
     565  class CombineMap : public MapBase<typename M1::Key, V, NC> {
    579566    typename SmartConstReference<M1>::Type m1;
    580567    typename SmartConstReference<M2>::Type m2;
    581568    F f;
    582569  public:
    583 
    584     typedef True NeedCopy;
    585     ///\e
    586     typedef typename M1::Key Key;
    587     ///\e
    588     typedef V Value;
     570    typedef MapBase<typename M1::Key, V, NC> Parent;
     571    typedef typename Parent::Key Key;
     572    typedef typename Parent::Value Value;
    589573
    590574    ///Constructor
     
    610594  ///
    611595  ///\relates CombineMap
    612   template<class M1,class M2,class F>
    613   inline CombineMap<M1,M2,F> combineMap(const M1 &m1,const M2 &m2,const F &f)
    614   {
    615     return CombineMap<M1,M2,F>(m1,m2,f);
     596  template<typename M1, typename M2, typename F, typename V>
     597  inline CombineMap<M1, M2, F, V, True>
     598  combineMap(const M1& m1,const M2& m2, const F& f) {
     599    return CombineMap<M1, M2, F, V, True>(m1,m2,f);
     600  }
     601
     602  template<typename M1, typename M2, typename F>
     603  inline CombineMap<M1, M2, F, typename F::result_type, True>
     604  combineMap(const M1& m1, const M2& m2, const F& f) {
     605    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
     606  }
     607
     608  template<typename M1, typename M2, typename K1, typename K2, typename V>
     609  inline CombineMap<M1, M2, V (*)(K1, K2), V, True>
     610  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
     611    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
    616612  }
    617613
     
    624620  ///The unary \c - operator must be defined for \c Value, of course.
    625621
    626   template<class M>
    627   class NegMap
    628   {
     622  template<typename M, typename NC = False>
     623  class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
    629624    typename SmartConstReference<M>::Type m;
    630625  public:
    631 
    632     typedef True NeedCopy;
    633     ///\e
    634     typedef typename M::Key Key;
    635     ///\e
    636     typedef typename M::Value Value;
     626    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     627    typedef typename Parent::Key Key;
     628    typedef typename Parent::Value Value;
    637629
    638630    ///Constructor
     
    645637  ///This function just returns a \ref NegMap class.
    646638  ///\relates NegMap
    647   template<class M>
    648   inline NegMap<M> negMap(const M &m)
    649   {
    650     return NegMap<M>(m);
     639  template <typename M>
     640  inline NegMap<M, True> negMap(const M &m) {
     641    return NegMap<M, True>(m);
    651642  }
    652643
     
    675666 
    676667
    677   template<class M>
    678   class AbsMap
    679   {
     668  template<typename M, typename NC = False>
     669  class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
    680670    typename SmartConstReference<M>::Type m;
    681671  public:
    682 
    683     typedef True NeedCopy;
    684     ///\e
    685     typedef typename M::Key Key;
    686     ///\e
    687     typedef typename M::Value Value;
     672    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     673    typedef typename Parent::Key Key;
     674    typedef typename Parent::Value Value;
    688675
    689676    ///Constructor
    690677    AbsMap(const M &_m) : m(_m) {};
    691     Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
     678    Value operator[](Key k) const {
     679      Value tmp = m[k];
     680      return tmp >= 0 ? tmp : -tmp;
     681    }
     682
    692683  };
    693684 
     
    696687  ///This function just returns a \ref AbsMap class.
    697688  ///\relates AbsMap
    698   template<class M>
    699   inline AbsMap<M> absMap(const M &m)
    700   {
    701     return AbsMap<M>(m);
     689  template<typename M>
     690  inline AbsMap<M, True> absMap(const M &m) {
     691    return AbsMap<M, True>(m);
    702692  }
    703693
     
    715705 
    716706
    717   template<class K,class V,class F>
    718   class FunctorMap
    719   {
     707  template<typename F,
     708           typename K = typename F::argument_type,
     709           typename V = typename F::result_type,
     710           typename NC = False>
     711  class FunctorMap : public MapBase<K, V, NC> {
    720712    const F &f;
    721713  public:
    722 
    723     typedef True NeedCopy;
    724     ///\e
    725     typedef K Key;
    726     ///\e
    727     typedef V Value;
     714    typedef MapBase<K, V, NC> Parent;
     715    typedef typename Parent::Key Key;
     716    typedef typename Parent::Value Value;
    728717
    729718    ///Constructor
     
    738727  ///The third template parameter isn't necessary to be given.
    739728  ///\relates FunctorMap
    740   template<class K,class V, class F>
    741   inline FunctorMap<K,V,F> functorMap(const F &f)
    742   {
    743     return FunctorMap<K,V,F>(f);
    744   }
     729  template<typename K, typename V, typename F> inline
     730  FunctorMap<F, K, V, True> functorMap(const F &f) {
     731    return FunctorMap<F, K, V, True>(f);
     732  }
     733
     734  template <typename F> inline
     735  FunctorMap<F, typename F::argument_type, typename F::result_type, True>
     736  functorMap(const F &f) {
     737    return functorMap<typename F::argument_type,
     738      typename F::result_type, F>(f);
     739  }
     740
     741  template <typename K, typename V> inline
     742  FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
     743    return functorMap<K, V, V (*)(K)>(f);
     744  }
     745
    745746
    746747  ///Converts a map to an STL style (unary) functor
     
    753754  ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
    754755
    755   template<class M>
    756   class MapFunctor
    757   {
     756  template <typename M, typename NC = False>
     757  class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
    758758    typename SmartConstReference<M>::Type m;
    759759  public:
    760 
    761     typedef True NeedCopy;
     760    typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     761    typedef typename Parent::Key Key;
     762    typedef typename Parent::Value Value;
     763
    762764    ///\e
    763765    typedef typename M::Key argument_type;
    764766    ///\e
    765767    typedef typename M::Value result_type;
    766     ///\e
    767     typedef typename M::Key Key;
    768     ///\e
    769     typedef typename M::Value Value;
    770768
    771769    ///Constructor
     
    781779  ///This function just returns a \ref MapFunctor class.
    782780  ///\relates MapFunctor
    783   template<class M>
    784   inline MapFunctor<M> mapFunctor(const M &m)
    785   {
    786     return MapFunctor<M>(m);
     781  template<typename M>
     782  inline MapFunctor<M, True> mapFunctor(const M &m) {
     783    return MapFunctor<M, True>(m);
    787784  }
    788785
     
    799796  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
    800797
    801   template<class M1,class M2>
    802   class ForkMap
    803   {
     798  template<typename  M1, typename M2, typename NC = False>
     799  class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    804800    typename SmartConstReference<M1>::Type m1;
    805801    typename SmartConstReference<M2>::Type m2;
    806802  public:
    807 
    808     typedef True NeedCopy;
    809     ///\e
    810     typedef typename M1::Key Key;
    811     ///\e
    812     typedef typename M1::Value Value;
     803    typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     804    typedef typename Parent::Key Key;
     805    typedef typename Parent::Value Value;
    813806
    814807    ///Constructor
    815808    ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
    816809    Value operator[](Key k) const {return m1[k];}
    817     void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);}
     810    //    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
    818811  };
    819812 
     
    825818  ///\relates ForkMap
    826819  ///\todo Wrong scope in Doxygen when \c \\relates is used
    827   template<class M1,class M2>
    828   inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2)
    829   {
    830     return ForkMap<M1,M2>(m1,m2);
     820  template <typename M1, typename M2>
     821  inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
     822    return ForkMap<M1, M2, True>(m1,m2);
    831823  }
    832824
     
    843835  ///its Value is <tt>bool</tt>.
    844836
    845   template<class M>
    846   class NotMap
    847   {
     837  template <typename M, typename NC = False>
     838  class NotMap : public MapBase<typename M::Key, bool, NC> {
    848839    typename SmartConstReference<M>::Type m;
    849840  public:
    850 
    851     typedef True NeedCopy;
    852     ///\e
    853     typedef typename M::Key Key;
    854     ///\e
    855     typedef bool Value;
     841    typedef MapBase<typename M::Key, bool, NC> Parent;
     842    typedef typename Parent::Key Key;
     843    typedef typename Parent::Value Value;
    856844
    857845    ///Constructor
     
    864852  ///This function just returns a \ref NotMap class.
    865853  ///\relates NotMap
    866   template<class M>
    867   inline NotMap<M> notMap(const M &m)
    868   {
    869     return NotMap<M>(m);
    870   }
    871 
    872 
    873 
    874 
    875 
    876 
     854  template <typename M>
     855  inline NotMap<M, True> notMap(const M &m) {
     856    return NotMap<M, True>(m);
     857  }
    877858
    878859
  • test/map_test.h

    r1435 r1675  
    5050      map[nodes.back()] = 23;
    5151    }
     52    map = constMap<Node>(12);
     53    for (int i = 0; i < (int)nodes.size(); ++i) {
     54      check(map[nodes[i]] == 12, "Wrong map constructor.");     
     55    }   
    5256    graph.clear();
    5357    nodes.clear();
     
    8791      }
    8892    }
     93    map = constMap<Edge>(12);
     94    for (int i = 0; i < (int)edges.size(); ++i) {
     95      check(map[edges[i]] == 12, "Wrong map constructor.");     
     96    }   
    8997    graph.clear();
    9098    edges.clear();   
  • test/maps_test.cc

    r1435 r1675  
    1010struct A {};
    1111struct B {};
    12 class F
    13 {
     12
     13class F {
    1414public:
     15  typedef A argument_type;
     16  typedef B result_type;
     17
    1518  B operator()(const A &) const {return B();}
    1619};
    1720
    1821int func(A) {return 3;}
     22
     23int binc(int, B) {return 4;}
    1924
    2025typedef ReadMap<A,double> DoubleMap;
     
    3944  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    4045
    41   checkConcept<ReadMap<A,B>, FunctorMap<A,B,F> >();
     46  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
    4247
    4348  int a;
     
    4752
    4853  B b;
    49   b=functorMap<A,B>(F())[A()];
     54  b=functorMap(F())[A()];
    5055
    51   a=functorMap<A,int>(&func)[A()];
     56  a=functorMap(&func)[A()];
    5257  check(a==3,"Something is wrong with functorMap");
     58
     59  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
     60  check(a==4,"Something is wrong with combineMap");
     61 
    5362
    5463  std::cout << __FILE__ ": All tests passed.\n";
Note: See TracChangeset for help on using the changeset viewer.