Re: [boost] Geometry/Vec lib swizzle syntax prototype

AMDG "Michael Fawcett" wrote:
I just implemented it locally. There are probably better ways. In particular I dislike the static variable, but I'm not sure how one could do away with it. Ideas are welcome!
template <typename X, typename Y, typename Z, typename W> struct vec4;
namespace detail {
template <typename X, typename Y = X, typename Z = Y, typename W = Z> struct address_of_dispatch { X *operator()(vec4<X, Y, Z, W> &rhs) const { return rhs.array(); } const X *operator()(const vec4<X, Y, Z, W> &rhs) const { return rhs.array(); } }; template <typename X, typename Y, typename Z, typename W> struct address_of_dispatch<X &, Y &, Z &, W &> { X *operator()(vec4<X &, Y &, Z &, W &> &rhs) const { static vec4<X, Y, Z, W> nrv; nrv = rhs; return nrv.array(); } const X *operator()(const vec4<X &, Y &, Z &, W &> &rhs) const { return (*this)(const_cast<vec4<X &, Y &, Z &, W &> &>(rhs)); } };
}
// Inside vec4's definition typename boost::remove_reference<X>::type *operator&(void) { return detail::address_of_dispatch<X, Y, Z, W>()(*this); } typename boost::remove_reference<X>::type const *operator&(void) const { return detail::address_of_dispatch<X, Y, Z, W>()(*this); }
That works...whether it's the best solution is another story...
Well, even whether it works is debatable. template<class X> void do_stuff(X*, X*); template<class X, class Y, class Z, class W> void f(vec4<X, Y, Z, W>&, vec4<X, Y, Z, W>&) { do_stuff(&arg1, &arg2); }
I'll update the Vault files to include these changes. Thanks for bringing this issue up!
--Michael Fawcett
In Christ, Steven Watanabe

On 12/2/06, Steven Watanabe <steven@providere-consulting.com> wrote:
Well, even whether it works is debatable.
template<class X> void do_stuff(X*, X*); template<class X, class Y, class Z, class W> void f(vec4<X, Y, Z, W>&, vec4<X, Y, Z, W>&) { do_stuff(&arg1, &arg2); }
Very good point. Did you have an alternate solution? It could possibly just be documented that it didn't work, or the address-of operator could static assert when the types are references. I don't have a strong opinion on this, in fact I hadn't even thought of it until Michael Marcin brought it up. --Michael Fawcett

On 12/2/06, Steven Watanabe <steven@providere-consulting.com> wrote:
AMDG
"Michael Fawcett" wrote:
<snip half-baked solution>
That works...whether it's the best solution is another story...
Well, even whether it works is debatable.
I removed the incorrect address-of operators from the Vault files. It shouldn't be too awful for end users to have to do float4 white = red.xxxw(); glColor4fv(&red); glColor4f(white.x, white.y, white.z, white.w); Although it would be very cool to make glColor4fv(&red.xxxw()) work. --Michael Fawcett
participants (2)
-
Michael Fawcett
-
Steven Watanabe