Hi all,

I'm trying to get the following code to work.
(This code is a simplified version of some algebraic type).
Is it possible to only declare one version of the 'apply' function?
Or should I declare the const version and the non-const version?

I tried using "inout", but I got the following error:

test.d(28): Error: inout method test.E.apply is not callable using a mutable object


class E
{
  void apply(void delegate(inout(E) e) f) inout
  {
    f(this);
  }

  int val;
}

void m()
{
  void setToZero(E e)
  {
    e.val = 0;
  }

  void printValue(const E e)
  {
    import std.stdio;
    writefln("Value: %s", e.val);
  }

  E obj;

  obj.apply(&setToZero);
  obj.apply(&printValue);
}

Thanks!

Reply via email to