From defbcdfe59e545b7562bcc7d033f3277d8791a04 Mon Sep 17 00:00:00 2001 From: Michael Stevens Date: Sun, 9 Oct 2005 16:43:42 +0000 Subject: [PATCH] FIX ref returned reference to 0 pointer if new element. Thanks Max Weinberg. [SVN r31247] --- include/boost/numeric/ublas/matrix_sparse.hpp | 7 ++++--- include/boost/numeric/ublas/vector_sparse.hpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index 36afd8a3..9ef8e9de 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -143,10 +143,11 @@ namespace boost { namespace numeric { namespace ublas { // Conversion to reference - may be invalidated BOOST_UBLAS_INLINE value_type& ref () const { - pointer p = (*this) ().find_element (i_, i_); + const pointer p = (*this) ().find_element (i_, i_); if (!p) - (*this) ().insert_element (i_, j_, value_type/*zero*/()); - return *p; + return (*this) ().insert_element (i_, j_, value_type/*zero*/()); + else + return *p; } private: diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index 04c4ef0f..82896c62 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -141,10 +141,11 @@ namespace boost { namespace numeric { namespace ublas { // Conversion to reference - may be invalidated BOOST_UBLAS_INLINE value_type& ref () const { - pointer p = (*this) ().find_element (i_); + const pointer p = (*this) ().find_element (i_); if (!p) - (*this) ().insert_element (i_, value_type/*zero*/()); - return *p; + return (*this) ().insert_element (i_, value_type/*zero*/()); + else + return *p; } private: