
2010/2/10 Agustín K-ballo Bergé <kaballo86@hotmail.com>:
El 09/02/2010 03:45 a.m., Emil Dotchevski escribió:
2010/2/8 Agustín K-ballo Bergé <kaballo86@hotmail.com>:
boost::la::la_detail::vref_< T > get( int index ) { return boost::la::vref( ... ); }
I was actually interested in the ... part :)
It's merely an expression that returns a T(&)[N].
Ah, I see. I'd just return T(&)[N] as in the code from my previous post; T(&)[N] is a conforming type already. You only need vref if all vectors/matrices in an expression are of built-in types: float v1[3] = { .... }; float v2[3] = { .... }; v1*v2; //error; you need vref(v1)*v2. but: float v1[3] = { .... }; boost::la::vec<float,3> v2=....; v1*v2; //okay
I have been bitten by the precedence issue to the point I enclose every pipe operation in parenthesis. And it gets worse if "complex swizzling expressions" are added to the library. Consider
( v1 | ( Y, -X ) ) * 2;
I don't think that such syntax is acceptable. I have to think about this but it seems to me that v1|Y-X should be possible (the currently supported syntax, for "non-complex" swizzling isn't v1|(Y,X), it is v1|YX.) Or we can throw op| out the window, I do hate it. Perhaps the best approach is to just use a function: vbind<YX>(v1) and let the user overload something if they want to.
It *might* be possible to get ride of the precedence problems by using expression templates, but even then subscripting operator seems more natural.
Operator [ ] is the best choice, but it can not be overloaded generically because it is required to be a member, for reasons that are beyond my understanding of C++. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode