Small improvements in maps.h
authorPeter Kovacs <kpeter@inf.elte.hu>
Tue, 08 Apr 2008 22:51:26 +0200
changeset 1238899d1891a3c
parent 116 b6bede534255
child 124 ae7785fe8431
Small improvements in maps.h
- Add a new version of constMap() function.
- Fix in FunctorToMap class.
lemon/maps.h
test/maps_test.cc
     1.1 --- a/lemon/maps.h	Thu Apr 03 13:00:18 2008 +0100
     1.2 +++ b/lemon/maps.h	Tue Apr 08 22:51:26 2008 +0200
     1.3 @@ -116,7 +116,7 @@
     1.4      /// Constructor with specified initial value
     1.5  
     1.6      /// Constructor with specified initial value.
     1.7 -    /// \param v is the initial value of the map.
     1.8 +    /// \param v The initial value of the map.
     1.9      ConstMap(const Value &v) : _value(v) {}
    1.10  
    1.11      /// Gives back the specified value.
    1.12 @@ -143,6 +143,11 @@
    1.13      return ConstMap<K, V>(v);
    1.14    }
    1.15  
    1.16 +  template<typename K, typename V>
    1.17 +  inline ConstMap<K, V> constMap() {
    1.18 +    return ConstMap<K, V>();
    1.19 +  }
    1.20 +
    1.21  
    1.22    template<typename T, T v>
    1.23    struct Const {};
    1.24 @@ -613,7 +618,7 @@
    1.25  	   typename K = typename F::argument_type,
    1.26  	   typename V = typename F::result_type>
    1.27    class FunctorToMap : public MapBase<K, V> {
    1.28 -    const F &_f;
    1.29 +    F _f;
    1.30    public:
    1.31      typedef MapBase<K, V> Parent;
    1.32      typedef typename Parent::Key Key;
     2.1 --- a/test/maps_test.cc	Thu Apr 03 13:00:18 2008 +0100
     2.2 +++ b/test/maps_test.cc	Tue Apr 08 22:51:26 2008 +0200
     2.3 @@ -83,20 +83,27 @@
     2.4    // ConstMap
     2.5    {
     2.6      checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
     2.7 +    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
     2.8      ConstMap<A,B> map1;
     2.9      ConstMap<A,B> map2(B());
    2.10      ConstMap<A,B> map3 = map1;
    2.11      map1 = constMap<A>(B());
    2.12 +    map1 = constMap<A,B>();
    2.13      map1.setAll(B());
    2.14 +    ConstMap<A,C> map4(C(1));
    2.15 +    ConstMap<A,C> map5 = map4;
    2.16 +    map4 = constMap<A>(C(2));
    2.17 +    map4.setAll(C(3));
    2.18  
    2.19      checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
    2.20      check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
    2.21  
    2.22      checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
    2.23 -    ConstMap<A,Const<int,10> > map4;
    2.24 -    ConstMap<A,Const<int,10> > map5 = map4;
    2.25 -    map4 = map5;
    2.26 -    check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap");
    2.27 +    ConstMap<A,Const<int,10> > map6;
    2.28 +    ConstMap<A,Const<int,10> > map7 = map6;
    2.29 +    map6 = constMap<A,int,10>();
    2.30 +    map7 = constMap<A,Const<int,10> >();
    2.31 +    check(map6[A()] == 10 && map7[A()] == 10, "Something is wrong with ConstMap");
    2.32    }
    2.33  
    2.34    // IdentityMap