lemon/concepts/maps.h
changeset 51 90201bb15a8d
parent 39 0a01d811071f
parent 48 93ae269876de
child 74 9394072da54f
equal deleted inserted replaced
3:e2ddb63393d5 5:0ad4181e9b28
    46       /// The value type of the map. (The type of objects associated with the keys).
    46       /// The value type of the map. (The type of objects associated with the keys).
    47       typedef T Value;
    47       typedef T Value;
    48 
    48 
    49       /// Returns the value associated with a key.
    49       /// Returns the value associated with a key.
    50 
    50 
       
    51       /// Returns the value associated with a key.
    51       /// \bug Value shouldn't need to be default constructible.
    52       /// \bug Value shouldn't need to be default constructible.
    52       ///
    53       ///
    53       Value operator[](const Key &) const {return Value();}
    54       Value operator[](const Key &) const {return Value();}
    54 
    55 
    55       template<typename _ReadMap>
    56       template<typename _ReadMap>
   111 	_WriteMap& m;
   112 	_WriteMap& m;
   112 
   113 
   113       };
   114       };
   114     };
   115     };
   115 
   116 
   116     /// Read/Writable map concept
   117     /// Read/writable map concept
   117     
   118     
   118     /// Read/writable map concept.
   119     /// Read/writable map concept.
   119     ///
   120     ///
   120     template<typename K, typename T>
   121     template<typename K, typename T>
   121     class ReadWriteMap : public ReadMap<K,T>,
   122     class ReadWriteMap : public ReadMap<K,T>,
   144   
   145   
   145     /// Dereferable map concept
   146     /// Dereferable map concept
   146     
   147     
   147     /// Dereferable map concept.
   148     /// Dereferable map concept.
   148     ///
   149     ///
       
   150     /// \todo Rethink this concept.
   149     template<typename K, typename T, typename R, typename CR>
   151     template<typename K, typename T, typename R, typename CR>
   150     class ReferenceMap : public ReadWriteMap<K,T>
   152     class ReferenceMap : public ReadWriteMap<K,T>
   151     {
   153     {
   152     public:
   154     public:
   153       /// Tag for reference maps.
   155       /// Tag for reference maps.
   163 
   165 
   164     protected:
   166     protected:
   165       Value tmp;
   167       Value tmp;
   166     public:
   168     public:
   167 
   169 
   168       ///Returns a reference to the value associated to a key.
   170       ///Returns a reference to the value associated with a key.
   169       Reference operator[](const Key &) { return tmp; }
   171       Reference operator[](const Key &) { return tmp; }
   170       ///Returns a const reference to the value associated to a key.
   172       ///Returns a const reference to the value associated with a key.
   171       ConstReference operator[](const Key &) const { return tmp; }
   173       ConstReference operator[](const Key &) const { return tmp; }
   172       /// Sets the value associated with a key.
   174       /// Sets the value associated with a key.
   173       void set(const Key &k,const Value &t) { operator[](k)=t; }
   175       void set(const Key &k,const Value &t) { operator[](k)=t; }
   174 
   176 
   175       /// \todo Rethink this concept. 
       
   176       template<typename _ReferenceMap>
   177       template<typename _ReferenceMap>
   177       struct ReferenceMapConcept {
   178       struct ReferenceMapConcept {
   178 
   179 
   179 	void constraints() {
   180 	void constraints() {
   180 	  checkConcept<ReadWriteMap, _ReferenceMap >();
   181 	  checkConcept<ReadWriteMap, _ReferenceMap >();