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 "inout"?

Thank you!

Reply via email to