ref returns and properties

Michiel Helvensteijn nomail at please.com
Sun Jan 25 11:32:59 PST 2009


Andrei Alexandrescu wrote:

> void move(ref T src, ref T dst);
> void swap(ref T lhs, ref T rhs);
> 
> ...
> 
> But if "prop" is a property with get and set, everything falls apart.
> Properties effectively hide the address of the actual data and only
> traffic in values. That's often good (and sometimes even the only
> possibility in the case of properties computed on-the-fly), but this
> abstraction effectively makes resource-conserving move and swap
> impossible.
> 
> ...
> 
> What to do? I'd like to refine the notion of property such that moving
> properties around is possible, without, however, complicating their
> interface too much.

I posted a possible solution to this (I think) in the last properties
thread. I was thinking that properties might be equiped with extra member
functions. One advantage is that you might get more efficiency. I think you
just named another.

class Host
{
     property prop
     {
         T get() { ... }
         void set(T value) { ... }
         void move(ref T dst) { ... }
         void swap(ref T rhs) { ... }
     }
}

Of course, in my idea (and my programming language), there is no difference
between f(a, b) and a.f(b), so that automatically works out. Not sure how
that would work out in D. One possibility is to just live with
Host.prop.move(dst).

-- 
Michiel




More information about the Digitalmars-d mailing list