Boost logo

Glas :

Re: [glas] A few more thoughts about return type of operator[](size_type) for sparse vectors

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2006-04-26 15:03:58

Christophe Sanz wrote:

> Conceptually, a vector is dense. Sparsity would just be a feature to
> exploit for implementation efficiency. Whether the vector appear as dense upon
> outputting all the elements does not imply that he is not stored as sparse.
> In the outputting case, the reference being const would be consistent. Now the
> question would be: when should a sparse vector change number nnz?

indeed if 'operator[](size_type)' would be a _const_ member function it
could return a const_reference (or a value_type) and thus using the
operator would not affect the sparsity. But is this acceptable for the
users? The whole discussion is similar to the operator[] of the
std::map. In the case of std::map, operator[] is only accessible on
non-const maps and only consulting the data associated to a key using
operator[] adds the key to the map (if it was not there already).

> I think I could see that the MTL deserve no room for changing nnz,


What do you mean exactly by this?