[Lemon-commits] Peter Kovacs: More exact concept checking for ma...

Lemon HG hg at lemon.cs.elte.hu
Sun Mar 16 08:35:43 CET 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/d73c2e8b25cb
changeset: 79:d73c2e8b25cb
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Sat Mar 15 20:21:21 2008 +0100
description:
	More exact concept checking for map concepts.

diffstat:

1 file changed, 52 insertions(+), 49 deletions(-)
lemon/concepts/maps.h |  101 +++++++++++++++++++++++++------------------------

diffs (214 lines):

diff -r fc178a057bbd -r d73c2e8b25cb lemon/concepts/maps.h
--- a/lemon/concepts/maps.h	Tue Feb 12 21:08:29 2008 +0000
+++ b/lemon/concepts/maps.h	Sat Mar 15 20:21:21 2008 +0100
@@ -29,7 +29,7 @@ namespace lemon {
 namespace lemon {
 
   namespace concepts {
-  
+
     /// \addtogroup concept
     /// @{
 
@@ -42,39 +42,39 @@ namespace lemon {
     {
     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<typename _ReadMap>
       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<typename K, typename T>
@@ -82,39 +82,37 @@ namespace lemon {
     {
     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 <typename _WriteMap>
       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<typename K, typename T>
@@ -123,14 +121,15 @@ namespace lemon {
     {
     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<typename _ReadWriteMap>
       struct Constraints {
@@ -140,13 +139,12 @@ namespace lemon {
 	}
       };
     };
-  
-  
+
+
     /// Dereferable map concept
-    
+
     /// Dereferable map concept.
     ///
-    /// \todo Rethink this concept.
     template<typename K, typename T, typename R, typename CR>
     class ReferenceMap : public ReadWriteMap<K,T>
     {
@@ -154,7 +152,7 @@ namespace lemon {
       /// 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 @@ namespace lemon {
       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<typename _ReferenceMap>
       struct Constraints {
 	void constraints() {
 	  checkConcept<ReadWriteMap<K, T>, _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;
       };
     };



More information about the Lemon-commits mailing list