]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a problem with iterators/references.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 17 Oct 2005 13:39:49 +0000 (13:39 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 17 Oct 2005 13:39:49 +0000 (13:39 +0000)
                                          * The constructor takes a pointer to
                                          * an accessor object that describes
                                          * which element of the matrix it
                                          * points to. This creates an
                                          * ambiguity when one writes code
                                          * like iterator->value()=0 (instead
                                          * of iterator->value()=0.0), since
                                          * the right hand side is an integer
                                          * that can both be converted to a
                                          * <tt>number</tt> (i.e., most
                                          * commonly a double) or to another
                                          * object of type
                                          * <tt>Reference</tt>. The compiler
                                          * then complains about not knowing
                                          * which conversion to take.
                                          *
                                          * For some reason, adding another
                                          * overload operator=(int) doesn't
                                          * seem to cure the problem. We avoid
                                          * it, however, by adding a second,
                                          * dummy argument to the Reference
                                          * constructor, that is unused, but
                                          * makes sure there is no second
                                          * matching conversion sequence using
                                          * a one-argument right hand side.
                                          *
                                          * The testcase oliver_01 checks that
                                          * this actually works as intended.

git-svn-id: https://svn.dealii.org/trunk@11609 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.html
deal.II/lac/include/lac/sparse_matrix.h

index 553d643ceb58896b8697b3ddc4caa2ff863f7996..46789a016a3559f163077ef5d684d6b555036817 100644 (file)
@@ -108,6 +108,16 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>lac</h3>
 
 <ol>
+  <li> <p>
+       Fixed: The <code class="class">SparseMatrix</code> iterators had a
+       problem when one wrote code like <code>iterator->value()=0</code>
+       (i.e. with a zero integer, rather than a floating point number on the
+       right), in that that opened up a second conversion sequence and the
+       compiler complained about an ambiguity. This is now fixed.
+       <br> 
+       (WB 2005/10/17)
+       </p>
+
   <li> <p>
        New: Now the class <code class="class">SparseILU</code> supports
        also the <code class="member">Tvmult</code> method. This feature
@@ -116,7 +126,6 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
        <br> 
        (Oliver Kayser-Herold 2005/09/15)
        </p>
-
 </ol>
 
 
index 1d98b18c19de6fa19b2fbd7456b2318794e0f0e4..7f8f547f6ec29464d029bb133198a043fdd686e6 100644 (file)
@@ -155,14 +155,46 @@ namespace internals
                                           * address of this matrix entry, we
                                           * have to go through functions to do
                                           * all this.
+                                          *
+                                          * The constructor takes a pointer to
+                                          * an accessor object that describes
+                                          * which element of the matrix it
+                                          * points to. This creates an
+                                          * ambiguity when one writes code
+                                          * like iterator->value()=0 (instead
+                                          * of iterator->value()=0.0), since
+                                          * the right hand side is an integer
+                                          * that can both be converted to a
+                                          * <tt>number</tt> (i.e., most
+                                          * commonly a double) or to another
+                                          * object of type
+                                          * <tt>Reference</tt>. The compiler
+                                          * then complains about not knowing
+                                          * which conversion to take.
+                                          *
+                                          * For some reason, adding another
+                                          * overload operator=(int) doesn't
+                                          * seem to cure the problem. We avoid
+                                          * it, however, by adding a second,
+                                          * dummy argument to the Reference
+                                          * constructor, that is unused, but
+                                          * makes sure there is no second
+                                          * matching conversion sequence using
+                                          * a one-argument right hand side.
+                                          *
+                                          * The testcase oliver_01 checks that
+                                          * this actually works as intended.
                                           */
         class Reference 
         {
           public:
                                              /**
-                                              * Constructor.
+                                              * Constructor. For the second
+                                              * argument, see the general
+                                              * class documentation.
                                               */
-            Reference (const Accessor *accessor);
+            Reference (const Accessor *accessor,
+                       const bool dummy);
 
                                              /**
                                               * Conversion operator to the
@@ -175,7 +207,7 @@ namespace internals
                                               * we presently point to to @p n.
                                               */
             const Reference & operator = (const number n) const;
-            
+
                                              /**
                                               * Add @p n to the element of the
                                               * matrix we presently point to.
@@ -275,6 +307,11 @@ namespace internals
                                       * denotes the underlying numeric type,
                                       * the second the constness of the
                                       * matrix.
+                                      *
+                                      * Since there is a specialization of
+                                      * this class for
+                                      * <tt>Constness=false</tt>, this class
+                                      * is for iterators to constant matrices.
                                      */
     template <typename number, bool Constness>
     class Iterator
@@ -1956,7 +1993,8 @@ namespace internals
     template <typename number>
     inline
     Accessor<number, false>::Reference::
-    Reference (const Accessor *accessor)
+    Reference (const Accessor *accessor,
+               const bool)
                     :
                     accessor (accessor)
     {}
@@ -2067,7 +2105,7 @@ namespace internals
     typename Accessor<number, false>::Reference
     Accessor<number, false>::value() const
     {
-      return this;
+      return Reference(this,true);
     }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.