How to make a generic function to take a class or struct by reference?
Ali Çehreli
acehreli at yahoo.com
Mon Mar 28 22:02:41 UTC 2022
On 3/27/22 22:32, vit wrote:
> int* getX(T)(return auto ref T t)
> if(is(T == class) || (is(T == struct) && __traits(isRef, t))){
> return &t.x;
> }
I also think 'return' parameter is needed but I could not come up with
an example where that 'return' provides any more safety. Compiler
already warns without it. (I tried with and without -preview=dip1000
-preview=dip25).
Ali
More information about the Digitalmars-d-learn
mailing list