COIN-OR::LEMON - Graph Library

Changeset 94:a4688e4138ec in lemon-1.2


Ignore:
Timestamp:
03/18/08 13:57:15 (16 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Fixes in the map concepts

  • Now Value type needn't be default constructible.
  • Extend the test file to check this.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/concepts/maps.h

    r79 r94  
    4848
    4949      /// Returns the value associated with the given key.
    50 
    51       /// Returns the value associated with the given key.
    52       /// \bug Value shouldn't need to be default constructible.
    53       Value operator[](const Key &) const { return Value(); }
     50      Value operator[](const Key &) const {
     51        return *static_cast<Value *>(0);
     52      }
    5453
    5554      template<typename _ReadMap>
     
    127126
    128127      /// Returns the value associated with the given key.
    129       Value operator[](const Key &) const { return Value(); }
     128      Value operator[](const Key &) const {
     129        return *static_cast<Value *>(0);
     130      }
    130131
    131132      /// Sets the value associated with the given key.
     
    161162      typedef CR ConstReference;
    162163
    163     protected:
    164       Value tmp;
    165164    public:
    166165
    167166      /// Returns a reference to the value associated with the given key.
    168       Reference operator[](const Key &) { return tmp; }
     167      Reference operator[](const Key &) {
     168        return *static_cast<Value *>(0);
     169      }
    169170
    170171      /// Returns a const reference to the value associated with the given key.
    171       ConstReference operator[](const Key &) const { return tmp; }
     172      ConstReference operator[](const Key &) const {
     173        return *static_cast<Value *>(0);
     174      }
    172175
    173176      /// Sets the value associated with the given key.
  • test/maps_test.cc

    r82 r94  
    3232inline bool operator<(A, A) { return true; }
    3333struct B {};
     34
     35class C {
     36  int x;
     37public:
     38  C(int _x) : x(_x) {}
     39};
    3440
    3541class F {
     
    5965  // Map concepts
    6066  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
     67  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
    6168  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
     69  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
    6270  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
     71  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
    6372  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
     73  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
    6474
    6575  // NullMap
Note: See TracChangeset for help on using the changeset viewer.