From 8a26759efbff9e194d0b58543a6c15fff58f5398 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 17 Oct 2005 13:39:49 +0000 Subject: [PATCH] Fix a problem with iterators/references. * 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 * number (i.e., most * commonly a double) or to another * object of type * Reference. 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 | 11 +++++- deal.II/lac/include/lac/sparse_matrix.h | 48 ++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 553d643ceb..46789a016a 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -108,6 +108,16 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

lac

    +
  1. + Fixed: The SparseMatrix iterators had a + problem when one wrote code like iterator->value()=0 + (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. +
    + (WB 2005/10/17) +

    +
  2. New: Now the class SparseILU supports also the Tvmult method. This feature @@ -116,7 +126,6 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
    (Oliver Kayser-Herold 2005/09/15)

    -
diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 1d98b18c19..7f8f547f6e 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -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 + * number (i.e., most + * commonly a double) or to another + * object of type + * Reference. 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 + * Constness=false, this class + * is for iterators to constant matrices. */ template class Iterator @@ -1956,7 +1993,8 @@ namespace internals template inline Accessor::Reference:: - Reference (const Accessor *accessor) + Reference (const Accessor *accessor, + const bool) : accessor (accessor) {} @@ -2067,7 +2105,7 @@ namespace internals typename Accessor::Reference Accessor::value() const { - return this; + return Reference(this,true); } -- 2.39.5