[LA] vector_traits for setters

Hi Emil and others, Qt 4.6 brought support for some vector and matrix types. While it is easy to define matrix_traits for QGenericMatrix and QMatrix4x4, i am struggling with the vector_traits for QVector2D, QVector3D and QVector4D. The problem is that Qt's vector types have setters and no non-const-ref getters. Is there a plan for (Boost).LA to support types with setters? cheers, Daniel Documentation for Qt's vector and matrix types can be found here: http://doc.qt.nokia.com/4.6/qmatrix4x4-members.html http://doc.qt.nokia.com/4.6/qgenericmatrix-members.html http://doc.qt.nokia.com/4.6/qvector2d-members.html http://doc.qt.nokia.com/4.6/qvector3d-members.html http://doc.qt.nokia.com/4.6/qvector4d-members.html

On Mon, May 10, 2010 at 12:58 PM, Daniel Pfeifer <daniel@pfeifer-mail.de> wrote:
The problem is that Qt's vector types have setters and no non-const-ref getters.
That is a problem isn't it. :)
Is there a plan for (Boost).LA to support types with setters?
The reason why the (Boost) LA vector traits set through references and not through setter functions is potentially better efficiency of in-place operations like +=, *= etc. But your feedback means that probably I should change the traits types to use setters. I think that it is unlikely for that change to lead to less efficient +=, *= etc. in practice. The change is probably very simple to make, and I was planning a new release soon anyway, I've implemented support for quaternions and a few new operations that seemed useful. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Hi Emil, Emil Dotchevski wrote:
On Mon, May 10, 2010 at 12:58 PM, Daniel Pfeifer <daniel@pfeifer-mail.de> wrote:
The problem is that Qt's vector types have setters and no non-const-ref getters.
(...) your feedback means that probably I should change the traits types to use setters.
We did exactly the same for Boost.Geometry (long ago). First have non-const-ref getters and lateron moved to setters... Seems it cannot be avoided. Regards, Barend

On 5/10/2010 9:10 PM, Barend Gehrels wrote:
Hi Emil,
Emil Dotchevski wrote:
On Mon, May 10, 2010 at 12:58 PM, Daniel Pfeifer <daniel@pfeifer-mail.de> wrote:
The problem is that Qt's vector types have setters and no non-const-ref getters. (...) your feedback means that probably I should change the traits types to use setters. We did exactly the same for Boost.Geometry (long ago). First have non-const-ref getters and lateron moved to setters... Seems it cannot be avoided.
Regards, Barend
Without studying proposed Boost.LA's extension mechanism, is it possible to use proxies for those vector/matrix types that only (natively) provide a setter interface? That is, if that manages to keep the Boost.LA interface convenient and/or improves efficiency for those types which do provide reference-to-non-const access to components... - Jeff

On Mon, May 10, 2010 at 10:35 PM, Jeffrey Lee Hellrung, Jr. <jhellrung@ucla.edu> wrote:
Without studying proposed Boost.LA's extension mechanism, is it possible to use proxies for those vector/matrix types that only (natively) provide a setter interface?
No, at least not in an efficient manner. Also, Boost LA has been carefully designed to avoid any use of proxy object instances and for that reason I would not want to use this approach. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Mon, May 10, 2010 at 9:10 PM, Barend Gehrels <barend@geodan.nl> wrote:
We did exactly the same for Boost.Geometry (long ago). First have non-const-ref getters and lateron moved to setters... Seems it cannot be avoided.
I'm interested to know why did you move to setters. (Regardless, as far as (Boost) LA is concerned, it seems like the use of setters over mutable references is being forced by the availability of matrix/vector types that don't provide mutable references interface.) Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Hi Emil, Emil Dotchevski wrote:
On Mon, May 10, 2010 at 9:10 PM, Barend Gehrels <barend@geodan.nl> wrote:
We did exactly the same for Boost.Geometry (long ago). First have non-const-ref getters and lateron moved to setters... Seems it cannot be avoided.
I'm interested to know why did you move to setters.
For the same reason as you did. Some classes do not support a public non-const reference and have a function like "set". I dived into old correspondations about this. Quoted (from Bruno):
- the problem is at least technically solvable by returning an assigner, that is an object with a reference to the point and that has the actual setting operation in its operator=.
But then:
The problem is that you can state: double& d = geometry::get(p); ...... lateron: d = 5;
So we decided to move to get/set to avoid this (maybe uncommon) scenario. Boost.Polygon does the same thing. Regards, Barend

On Tue, May 11, 2010 at 6:07 AM, Barend Gehrels <barend@geodan.nl> wrote:
The problem is that you can state: double& d = geometry::get(p); ...... lateron: d = 5;
Why is this a problem? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Tue, May 11, 2010 at 11:11 AM, Daniel Pfeifer <daniel@pfeifer-mail.de> wrote:
The problem is that you can state: double& d = geometry::get(p); ...... lateron: d = 5;
Why is this a problem?
As long as geometry::get returns a reference, there is no problem. If it is a proxy, there is.
What is the problem? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Mon, May 10, 2010 at 12:58 PM, Daniel Pfeifer <daniel@pfeifer-mail.de> wrote:
Hi Emil and others,
Qt 4.6 brought support for some vector and matrix types.
While it is easy to define matrix_traits for QGenericMatrix and QMatrix4x4, i am struggling with the vector_traits for QVector2D, QVector3D and QVector4D.
The problem is that Qt's vector types have setters and no non-const-ref getters.
Is there a plan for (Boost).LA to support types with setters?
I started converting to setters and hit a problem I don't have a good solution to. (Boost)LA uses operator| overloads to bind vector and matrix type (elements). For example, for an object v of any vector type you could say: v|row_matrix and it returns a reference to v itself of type that makes it look like a row-matrix. Importantly, this reference is not read-only. Similarly, you could say v|X and it returns a reference to the X element of v. Naturally, you could do: v|X *= 2; to multiply the X coordinate of v by 2. This syntax depends on the vector_traits type to return a mutable reference to a vector's element. This won't work with setters. Ideas? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (4)
-
Barend Gehrels
-
Daniel Pfeifer
-
Emil Dotchevski
-
Jeffrey Lee Hellrung, Jr.