On Saturday, 2 February 2013 at 03:50:49 UTC, Zach the Mystic wrote:
[..]

Then, if we used your proposed nested structs to implement properties, pretty weird things like this would become possible:

struct A
{
  int _value;

  struct B
  {
    int get() { return _value; }
    alias this = get;

    void opAssign(int v) { _value = v; }
  }

  B length;
}

void func(T)(ref A a, T oldLength)
{
  a.length = 100;
  // Trying to restore 'a' back to the old length:
  a.length = oldLength;
}

void main()
{
  A a;
  a.length = 5;
  func(a, a.length);
  assert(a.length == 100);
}

Reply via email to