diff --git a/include/boost/numeric/ublas/storage_sparse.hpp b/include/boost/numeric/ublas/storage_sparse.hpp index f4867f48..9fbb3d8f 100644 --- a/include/boost/numeric/ublas/storage_sparse.hpp +++ b/include/boost/numeric/ublas/storage_sparse.hpp @@ -378,7 +378,7 @@ namespace boost { namespace numeric { namespace ublas { // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. std::pair insert (const value_type &p) { iterator it = detail::lower_bound (begin (), end (), p, detail::less_pair ()); - if (it->first == p.first) + if (it != end () && it->first == p.first) return std::make_pair (it, false); difference_type n = it - begin (); BOOST_UBLAS_CHECK (size () == 0 || size () == size_type (n), external_logic ());