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

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 17:08:49 UTC, realhet wrote: On Sunday, 20 September 2020 at 16:18:19 UTC, Steven Schveighoffer wrote: 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: Yeah, I think

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

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 16:18:19 UTC, Steven Schveighoffer wrote: 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: Yeah, I think this might work. -Steve That would be a 3rd category out i

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

2020-09-20 Thread Steven Schveighoffer via Digitalmars-d-learn
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 t

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

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 15:52:49 UTC, realhet wrote: On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote: On 9/20/20 9:30 AM, realhet wrote: I managed to do the constant swizzles and it seems so elegant: auto opDispatch(string def)() const if(validRvalueSwizzl

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

2020-09-20 Thread realhet via Digitalmars-d-learn
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++; I want to make a similar type like the GLSL vectors. Where the following thing is valid: vec4 a, b;

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

2020-09-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/20/20 9:30 AM, realhet wrote: Hi, struct S{   int[2] array;   ref  x()   { return array[0]; }   auto x() const { return array[0]; } } If there a way to write the function 'x' into one function, not 2 overloads. I tried auto/const/ref mindlessly :D, also remembered 'inout', but

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

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 13:30:36 UTC, realhet wrote: Hi, More specifically: struct S{ int[2] array; ref swizzle(string code)(){ static if(code=="x") return array[0]; else static if(code=="y") return array[1]; else static assert("Unhandled"); }

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

2020-09-20 Thread realhet via Digitalmars-d-learn
Hi, struct S{ int[2] array; ref x() { return array[0]; } auto x() const { return array[0]; } } If there a way to write the function 'x' into one function, not 2 overloads. I tried auto/const/ref mindlessly :D, also remembered 'inout', but obviously those weren't solve the probl