
On 12/1/06, Michael Marcin <mmarcin@method-solutions.com> wrote:
Very cool! I know nothing about the PP library so it is very hard for me to decipher what the code is doing. If I were to write:
float4 red( 1, 0, 0, 1 ); 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): typename boost::enable_if<boost::is_reference<X>, const boost::remove_reference<X>::type *>::type operator&() const { static vec4<boost::remove_reference<X>::type> nrv; nrv = *this; return nrv.array(); } The actual address to the array of references hardly seems useful, while the behavior you showed seems very useful, and a user can always get around it using boost::address_of. --Michael Fawcett