On Wednesday, 6 August 2025 at 15:43:01 UTC, Brother Bill wrote:
How is this done in D?

I thought the following would work, but the compiler doesn't like `this.count` as a default argument:

```d
struct Counter {
   int count;

   void incrementBy(int increment, int preCount = this.count)
   in {
      assert(increment >= 0, "increment must be zero or greater");
   }
   out {
       assert(count == preCount + increment);
   }
   do {
      this.count += increment;
   }
}
```

And I expect you'd like to avoid adding a function parameter anyway.
  • Design by Contra... Brother Bill via Digitalmars-d-learn
    • Re: Design ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Design ... Nick Treleaven via Digitalmars-d-learn

Reply via email to