COIN-OR::LEMON - Graph Library

Ticket #38: constmap.patch

File constmap.patch, 2.5 KB (added by Peter Kovacs, 16 years ago)

Patch for constMap() functions and FunctorToMap?

  • lemon/maps.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1207687886 -7200
    # Node ID 8899d1891a3c63a87d251d8dde847c308e741c34
    # Parent  b6bede534255e492871c601771442b65e12f7319
    Small improvements in maps.h
    - Add a new version of constMap() function.
    - Fix in FunctorToMap class.
    
    diff -r b6bede534255 -r 8899d1891a3c lemon/maps.h
    a b  
    116116    /// Constructor with specified initial value
    117117
    118118    /// Constructor with specified initial value.
    119     /// \param v is the initial value of the map.
     119    /// \param v The initial value of the map.
    120120    ConstMap(const Value &v) : _value(v) {}
    121121
    122122    /// Gives back the specified value.
     
    141141  template<typename K, typename V>
    142142  inline ConstMap<K, V> constMap(const V &v) {
    143143    return ConstMap<K, V>(v);
     144  }
     145
     146  template<typename K, typename V>
     147  inline ConstMap<K, V> constMap() {
     148    return ConstMap<K, V>();
    144149  }
    145150
    146151
     
    613618           typename K = typename F::argument_type,
    614619           typename V = typename F::result_type>
    615620  class FunctorToMap : public MapBase<K, V> {
    616     const F &_f;
     621    F _f;
    617622  public:
    618623    typedef MapBase<K, V> Parent;
    619624    typedef typename Parent::Key Key;
  • test/maps_test.cc

    diff -r b6bede534255 -r 8899d1891a3c test/maps_test.cc
    a b  
    8383  // ConstMap
    8484  {
    8585    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
     86    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    8687    ConstMap<A,B> map1;
    8788    ConstMap<A,B> map2(B());
    8889    ConstMap<A,B> map3 = map1;
    8990    map1 = constMap<A>(B());
     91    map1 = constMap<A,B>();
    9092    map1.setAll(B());
     93    ConstMap<A,C> map4(C(1));
     94    ConstMap<A,C> map5 = map4;
     95    map4 = constMap<A>(C(2));
     96    map4.setAll(C(3));
    9197
    9298    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
    9399    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
    94100
    95101    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
    96     ConstMap<A,Const<int,10> > map4;
    97     ConstMap<A,Const<int,10> > map5 = map4;
    98     map4 = map5;
    99     check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap");
     102    ConstMap<A,Const<int,10> > map6;
     103    ConstMap<A,Const<int,10> > map7 = map6;
     104    map6 = constMap<A,int,10>();
     105    map7 = constMap<A,Const<int,10> >();
     106    check(map6[A()] == 10 && map7[A()] == 10, "Something is wrong with ConstMap");
    100107  }
    101108
    102109  // IdentityMap