Re: [eigen] Commenting issue #110, disabling operator[] for matrices

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


In my opinion matrix(i) should be disallowed as well, I'd guess in
most of the cases matrix(i) means that the user mistakenly believes
the matrix to be a vector. I'd go for the more verbose but
self-documenting .asVector(i).

Just my two cents.

Marton

On 22 April 2010 14:34, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> Hi,
>
> https://bitbucket.org/eigen/eigen/issue/110/disabling-operator-for-a-matrix
>
> here we are discussing disabling operator[] on matrices.
>
> We can perfectly disable it on matrices while keeping it on vectors
> (e.g. with a static assertion).
>
> The motivation for disabling it on matrices is to guard against this
> dreadful c++ code:
>
>   matrix[i,j]
>
> which in c++ compiles as
>
>   matrix[i]
>
> which addresses the i-th entry in the storage order of the matrix.
>
> If you want that functionality, there still is the synonym
>
>  matrix(i)
>
> And the method coeff(int) if you want to avoid the assertion.
>
> People have already proposed adding an expression to view a matrix as
> a vector, following its storage order. But you can already do that
> with Map. If you really want, we can add a conveniene method
> asVector() to return such a Map object. But given the possibility of
> doing matrix(index), i don't see too much motivation for that...
>
> Benoit
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/