# HG changeset patch # User Peter Kovacs # Date 2008-03-15 20:21:21 # Node ID d73c2e8b25cb0eb089f1559e928ac9f5b06751a2 # Parent fc178a057bbdcaf846d2ec952c9e16e38be2eed6 More exact concept checking for map concepts. diff --git a/lemon/concepts/maps.h b/lemon/concepts/maps.h --- a/lemon/concepts/maps.h +++ b/lemon/concepts/maps.h @@ -29,7 +29,7 @@ namespace lemon { namespace concepts { - + /// \addtogroup concept /// @{ @@ -42,39 +42,39 @@ { public: /// The key type of the map. - typedef K Key; + typedef K Key; /// The value type of the map. (The type of objects associated with the keys). typedef T Value; - /// Returns the value associated with a key. + /// Returns the value associated with the given key. - /// Returns the value associated with a key. - /// \bug Value shouldn't need to be default constructible. - /// - Value operator[](const Key &) const {return Value();} + /// Returns the value associated with the given key. + /// \bug Value shouldn't need to be default constructible. + Value operator[](const Key &) const { return Value(); } template struct Constraints { void constraints() { Value val = m[key]; val = m[key]; - typename _ReadMap::Value own_val = m[own_key]; - own_val = m[own_key]; + typename _ReadMap::Value own_val = m[own_key]; + own_val = m[own_key]; + ignore_unused_variable_warning(key); ignore_unused_variable_warning(val); + ignore_unused_variable_warning(own_key); ignore_unused_variable_warning(own_val); - ignore_unused_variable_warning(key); } - Key& key; - typename _ReadMap::Key& own_key; - _ReadMap& m; + const Key& key; + const typename _ReadMap::Key& own_key; + const _ReadMap& m; }; - + }; /// Writable map concept - + /// Writable map concept. /// template @@ -82,39 +82,37 @@ { public: /// The key type of the map. - typedef K Key; + typedef K Key; /// The value type of the map. (The type of objects associated with the keys). typedef T Value; - /// Sets the value associated with a key. - void set(const Key &,const Value &) {} + /// Sets the value associated with the given key. + void set(const Key &, const Value &) {} - ///Default constructor + /// Default constructor. WriteMap() {} template struct Constraints { void constraints() { - // No constraints for constructor. m.set(key, val); m.set(own_key, own_val); + ignore_unused_variable_warning(key); ignore_unused_variable_warning(val); ignore_unused_variable_warning(own_key); ignore_unused_variable_warning(own_val); } - - Value& val; - typename _WriteMap::Value own_val; - Key& key; - typename _WriteMap::Key& own_key; + const Key& key; + const Value& val; + const typename _WriteMap::Key& own_key; + const typename _WriteMap::Value own_val; _WriteMap& m; - }; }; /// Read/writable map concept - + /// Read/writable map concept. /// template @@ -123,14 +121,15 @@ { public: /// The key type of the map. - typedef K Key; + typedef K Key; /// The value type of the map. (The type of objects associated with the keys). typedef T Value; - /// Returns the value associated with a key. - Value operator[](const Key &) const {return Value();} - /// Sets the value associated with a key. - void set(const Key & ,const Value &) {} + /// Returns the value associated with the given key. + Value operator[](const Key &) const { return Value(); } + + /// Sets the value associated with the given key. + void set(const Key &, const Value &) {} template struct Constraints { @@ -140,13 +139,12 @@ } }; }; - - + + /// Dereferable map concept - + /// Dereferable map concept. /// - /// \todo Rethink this concept. template class ReferenceMap : public ReadWriteMap { @@ -154,7 +152,7 @@ /// Tag for reference maps. typedef True ReferenceMapTag; /// The key type of the map. - typedef K Key; + typedef K Key; /// The value type of the map. (The type of objects associated with the keys). typedef T Value; /// The reference type of the map. @@ -166,33 +164,38 @@ Value tmp; public: - ///Returns a reference to the value associated with a key. + /// Returns a reference to the value associated with the given key. Reference operator[](const Key &) { return tmp; } - ///Returns a const reference to the value associated with a key. + + /// Returns a const reference to the value associated with the given key. ConstReference operator[](const Key &) const { return tmp; } - /// Sets the value associated with a key. + + /// Sets the value associated with the given key. void set(const Key &k,const Value &t) { operator[](k)=t; } template struct Constraints { void constraints() { checkConcept, _ReferenceMap >(); + ref = m[key]; m[key] = val; - val = m[key]; m[key] = ref; - ref = m[key]; + m[key] = cref; + own_ref = m[own_key]; m[own_key] = own_val; - own_val = m[own_key]; m[own_key] = own_ref; - own_ref = m[own_key]; + m[own_key] = own_cref; + m[key] = m[own_key]; + m[own_key] = m[key]; } - - typename _ReferenceMap::Key& own_key; + const Key& key; + Value& val; + Reference ref; + ConstReference cref; + const typename _ReferenceMap::Key& own_key; typename _ReferenceMap::Value& own_val; typename _ReferenceMap::Reference own_ref; - Key& key; - Value& val; - Reference ref; + typename _ReferenceMap::ConstReference own_cref; _ReferenceMap& m; }; };