Boost logo

Boost :

From: Michael Marcin (mike_at_[hidden])
Date: 2006-12-04 18:46:15


Michael Fawcett wrote:
> On 12/1/06, Michael Marcin <mmarcin_at_[hidden]> wrote:
>> 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.
>
> In another posting it was pointed out that taking the address of a
> function's return is generally not done for specifically this reason
> (among others). Should there be any effort to solve this or just
> leave the swizzle functions as is?
>
> We could put a static assert in the address-of operator for when the
> underlying types are references...but again, I think there is
> precedent in coding guidelines to not do:
>
> &red.xxxw(); // taking the address of a temporary
>
> int add(int lhs, int rhs)
> {
> int result = lhs + rhs;
> return result;
> }
>
> int *p = &add(5, 5);
>
> This has never been expected to work. IMHO I don't think the swizzle
> functions should be expected to behave any differently.
>

How about red.xxxw().data()?

- Michael Marcin


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