On Sunday, 18 December 2022 at 16:21:05 UTC, Salih Dincer wrote:
Don't you think it's interesting that it doesn't need unary operator overloading?

```d
import std.stdio;

struct S
{
  int value;

  alias opCall this;
  this(int i) {
    value = i;
  }

  alias opAssign = opCall;
  @property opCall(int x) {
    return value = x;
  }

  @property opCall() inout {
    return value;
  }

  @property opOpAssign(string op)(int x) {
    write(":"); // came here before
    mixin("return value"~op~"=x;");
  }
  // no need: opUnary(string op)();
}

void main()
{

  S a = S(10),
    b = S(-1);

  writeln(a + b); // 9
  writeln(++a + b); // :10

  a += 10; // :

  assert(a == 21);
  writeln("\n--");

  writeln(-b); // 1
}
```
SDB@79



Why are you using @property everywhere?

Reply via email to