Will D ever get a reference type?

BCS ao at pathlink.com
Mon Jul 30 16:41:05 PDT 2007


Reply to Bill,

> I posit that what you really want most of the time is to return
> something to the caller that acts just like a Foo, but still gives you
> some control, perhaps in the form of preventing certain operations,
> and/or giving you a way to observe modifications.

if typedef's could overload opXxx functions then they could serve as the 
restriction proxy

(just making up a syntax here)

|template Range(int min, int max)
|{
|  typedef int Range
|  {
|    ref Range opAssign(int i)
|    {
|      if(min > i || max < i) throw new RangeError();
|      super = i;
|    }
|  }
|}
|
|class C
|{
|  int i;
|
|  ref Range!(5, 12) getRef(){return i;}
|}
|
|class C;
|c.getRef = 14; // fails

this would all be done at compile time





More information about the Digitalmars-d mailing list