## Glas :## Re: [glas] return type of operator[](size_type) for sparse vectors? |

**From:** Russell Smiley (*smiley_at_[hidden]*)

**Date:** 2006-04-26 15:11:21

**Next message:**Toon Knapen: "Re: [glas] [boost] Possible class submission: Sparse Array"**Previous message:**Toon Knapen: "Re: [glas] A few more thoughts about return type of operator[](size_type) for sparse vectors"**Maybe in reply to:**Toon Knapen: "[glas] return type of operator[](size_type) for sparse vectors?"**Next in thread:**Peter Gottschling: "Re: [glas] return type of operator[](size_type) for sparse vectors?"**Reply:**Peter Gottschling: "Re: [glas] return type of operator[](size_type) for sparse vectors?"**Reply:**Toon Knapen: "Re: [glas] return type of operator[](size_type) for sparse vectors?"

I think I prefer option 3 (proxy that modifies a structural zero if

necessary). Presumably there is some penalty for this more sophisticated

behaviour.

If "proxy_type operator[]" is not provided how would structural zeroes

normally be modified?

Russell.

> -----Original Message-----

> Subject: [glas] return type of operator[](size_type) for

> sparse vectors?

>

>

> Given a sparse vector v of size 10, what would v[0] 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.

>

**Next message:**Toon Knapen: "Re: [glas] [boost] Possible class submission: Sparse Array"**Previous message:**Toon Knapen: "Re: [glas] A few more thoughts about return type of operator[](size_type) for sparse vectors"**Maybe in reply to:**Toon Knapen: "[glas] return type of operator[](size_type) for sparse vectors?"**Next in thread:**Peter Gottschling: "Re: [glas] return type of operator[](size_type) for sparse vectors?"**Reply:**Peter Gottschling: "Re: [glas] return type of operator[](size_type) for sparse vectors?"**Reply:**Toon Knapen: "Re: [glas] return type of operator[](size_type) for sparse vectors?"