Alias this property for getter and setter?
sighoya
sighoya at gmail.com
Thu Mar 21 08:56:44 UTC 2019
I would like to alias this with properties in both directions
such that this is not only destructured to the other value but
also the other value is destructured to this.
My intention is to allow something like the following:
struct Ref(T)
{
T* ptr;
this(T* ptr)
{
this.ptr=ptr;
}
@property T convert()
{
return *ptr;
}
@property Ref!T convert(ref T t)
{
return Ref!T(&t);
}
alias convert this;
}
T sum(T)(SList!(Ref!T) list) if(T is Number)
{
T sum=0;
foreach(T elem; list)
{
sum+=elem;
}
return sum;
}
void testRef()
{
int i=2;
Ref!int reference=i;
int j=reference;
}
More information about the Digitalmars-d
mailing list