
On 12/1/06, Michael Fawcett <michael.fawcett@gmail.com> wrote:
On 12/1/06, Michael Marcin <mmarcin@method-solutions.com> wrote:
glColor4fv( (float*)&red ); // make color red glColor4fv( (float*)&red.xxxw() ); // make color white
would this work? I'm guessing red would and white would not.
You are correct. The actual type returned by red.xxxw() wold be vec4<float &>, although that just gave me an idea. What about overloading the address of operator when the underlying type is a reference? Something like (off the top of my head...not well thought out):
<snip untested code> 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... I'll update the Vault files to include these changes. Thanks for bringing this issue up! --Michael Fawcett