[Dune-devel] [Dune-Commit] [Commit] dune-common - cca8ac1: [bugfix] fix bug #1457 - FieldVector::operator*=() called with an int is ambiguous

Christian Engwer christian.engwer at uni-muenster.de
Tue May 20 14:57:59 CEST 2014


I added short comments refereing to the bug report.

On Tue, May 20, 2014 at 02:46:43PM +0200, Oliver Sander wrote:
> Hi Christian, Marco,
> thanks for fixing this.  However, can we have some in-code documentation with this patch?
> The bug is fixes is so subtle that I'm afraid nobody will understand why the enable_if-trick
> is used here in short time.
> Thanks,
> Oliver
> 
> Am 20.05.2014 14:40, schrieb Christian Engwer:
> > New commit, appeared at Tue May 20 14:40:52 2014 +0200
> > as part of the following ref changes:
> > 
> >     branch refs/heads/master    updated from cf4bf4d -> b6ddd1c
> > 
> > Browsable version: http://cgit.dune-project.org/repositories/dune-common/commit/?id=cca8ac1bf824be51aefc48f67d6050c44a682f93
> > 
> > ======================================================================
> > 
> > commit cca8ac1bf824be51aefc48f67d6050c44a682f93
> > Author:     Marco Cecchetti <mc.aquilegia at gmail.com>
> > AuthorDate: Sat May 17 22:39:05 2014 +0200
> > Commit:     Christian Engwer <christi at dune-project.org>
> > CommitDate: Tue May 20 14:37:38 2014 +0200
> > 
> >     [bugfix] fix bug #1457 - FieldVector::operator*=() called with an int is ambiguous
> >     
> >     The bug affected operators: +=, -=, *=, /=. It has been fixed by using:
> >     enable_if<is_convertible<ParamType, FieldVector::valueType>, ...>
> > 
> >  dune/common/densevector.hh      | 41 +++++++++++++++++++++++++++++++++--------
> >  dune/common/test/fvectortest.cc |  2 ++
> >  2 files changed, 35 insertions(+), 8 deletions(-)
> > 
> > 
> > 
> > diff --git a/dune/common/densevector.hh b/dune/common/densevector.hh
> > index 7a30b27..7ef0ec0 100644
> > --- a/dune/common/densevector.hh
> > +++ b/dune/common/densevector.hh
> > @@ -4,6 +4,7 @@
> >  #define DUNE_DENSEVECTOR_HH
> >  
> >  #include <limits>
> > +#include <type_traits>
> >  
> >  #include "genericiterator.hh"
> >  #include "ftraits.hh"
> > @@ -406,32 +407,56 @@ namespace Dune {
> >      }
> >  
> >      //! vector space add scalar to all comps
> > -    derived_type& operator+= (const value_type& k)
> > -    {
> > +    template <typename ValueType>
> > +    typename std::enable_if<
> > +      std::is_convertible<ValueType, value_type>::value,
> > +      derived_type
> > +    >::type&
> > +    operator+= (const ValueType& kk)
> > +    {
> > +      const value_type& k = kk;
> >        for (size_type i=0; i<size(); i++)
> >          (*this)[i] += k;
> >        return asImp();
> >      }
> >  
> >      //! vector space subtract scalar from all comps
> > -    derived_type& operator-= (const value_type& k)
> > -    {
> > +    template <typename ValueType>
> > +    typename std::enable_if<
> > +      std::is_convertible<ValueType, value_type>::value,
> > +      derived_type
> > +    >::type&
> > +    operator-= (const ValueType& kk)
> > +    {
> > +      const value_type& k = kk;
> >        for (size_type i=0; i<size(); i++)
> >          (*this)[i] -= k;
> >        return asImp();
> >      }
> >  
> >      //! vector space multiplication with scalar
> > -    derived_type& operator*= (const value_type& k)
> > -    {
> > +    template <typename ValueType>
> > +    typename std::enable_if<
> > +      std::is_convertible<ValueType, value_type>::value,
> > +      derived_type
> > +    >::type&
> > +    operator*= (const ValueType& kk)
> > +    {
> > +      const value_type& k = kk;
> >        for (size_type i=0; i<size(); i++)
> >          (*this)[i] *= k;
> >        return asImp();
> >      }
> >  
> >      //! vector space division by scalar
> > -    derived_type& operator/= (const value_type& k)
> > -    {
> > +    template <typename ValueType>
> > +    typename std::enable_if<
> > +      std::is_convertible<ValueType, value_type>::value,
> > +      derived_type
> > +    >::type&
> > +    operator/= (const ValueType& kk)
> > +    {
> > +      const value_type& k = kk;
> >        for (size_type i=0; i<size(); i++)
> >          (*this)[i] /= k;
> >        return asImp();
> > diff --git a/dune/common/test/fvectortest.cc b/dune/common/test/fvectortest.cc
> > index e182145..4a323df 100644
> > --- a/dune/common/test/fvectortest.cc
> > +++ b/dune/common/test/fvectortest.cc
> > @@ -366,6 +366,8 @@ int main()
> >      FieldVectorTest<int, 3>();
> >      FieldVectorTest<float, 3>();
> >      FieldVectorTest<double, 3>();
> > +    FieldVectorTest<int, 1>();
> > +    FieldVectorTest<double, 1>();
> >  
> >      test_nan();
> >      test_infinity_norms();
> > 
> > _______________________________________________
> > Dune-Commit mailing list
> > Dune-Commit at dune-project.org
> > http://lists.dune-project.org/mailman/listinfo/dune-commit
> > 
> 
> 



> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel


-- 
Prof. Dr. Christian Engwer 
Institut für Numerische und Angewandte Mathematik
Fachbereich Mathematik und Informatik der Universität Münster
Einsteinstrasse 62
48149 Münster

E-Mail	christian.engwer at uni-muenster.de
Telefon	+49 251 83-35067
FAX		+49 251 83-32729




More information about the Dune-devel mailing list