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

realhet real_het at
Sun Sep 20 13:44:10 UTC 2020

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");

To make this work for const/immutable structs, I have to make 
another function with the header: auto swizzle(string code)() 
const{ copy or mixin the whole thing again... }

Maybe there is a language feature for this, like "auto ref" or 

Thank you!

More information about the Digitalmars-d-learn mailing list