Is there a way to return an lvalue and also an rvalue from the same member function?

Steven Schveighoffer schveiguy at gmail.com
Sun Sep 20 16:18:19 UTC 2020


On 9/20/20 11:52 AM, realhet wrote:
> On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote:
>> On 9/20/20 9:30 AM, realhet wrote:
>> ref inout(int) x() inout { return array[0]; }
> 
> This doesn't work when I type:
> v.x++;

It should, as long as v is mutable.

> I want to make a similar type like the GLSL vectors. Where the following 
> thing is valid:
> vec4 a, b;
> a.yzw = b.xzy;

This should be straight-up opDispatch I would think. You might need a 
helper return that reroutes the correct items.

> The only thing I don't want  to implement from the GLSL spec is those 
> non-contigous swizzle assignments like:
> a.zyx = vec3(1,2,3) ***
> but
> a.xyz = vec3(1,2,3) should work.

What you could do, in this case, is make your return type either a 
helper type that uses a slice of the original, or one that contains a 
copy of the data in the right order, but is not assignable.

> 
> *** maybe with a struct that refers to the original vector and the 
> swizzle code it could be also possible. :D

Yeah, I think this might work.

-Steve


More information about the Digitalmars-d-learn mailing list