Boost logo

Boost :

From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2006-12-01 16:31:55


On 12/1/06, Michael Marcin <mmarcin_at_[hidden]> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk