[glas] return type of operator(size_type) for sparse vectors?
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2006-04-25 15:22:23
Given a sparse vector v of size 10, what would v return? Should it
return a reference to the element at position 0 in the sparse vector.
What if that element is a structural-zero? It clearly is not as
straightforward as with dense vectors.
The options AFAICT are:
1) provide no 'operator(size_type)' to avoid confusion
2) return the value at the corresponding position or if the position
corresponds to a structural-zero return zero. Thus in that case
operator will not affect/change the structure and operator will not
allow to change the value at the corresponding position.
3) return a proxy. If the proxy is being assigned to, the structure will
be changed in case the position corresponded with a structural-zero.
What would you find most intuitive? (of course other methods allow to
query if a specific position corresponds to a non-zero or not so
operator is not the only way to access elements). Also your feedback
on you experience with other libraries can be usefull to make the right