Design by Contract - out old struct member value
Brother Bill
brotherbill at mail.com
Wed Aug 6 15:43:01 UTC 2025
Lets say we have the member function incrementBy(int increment)
```
struct Counter {
int count;
void incrementBy(int increment)
in {
assert(increment >= 0, "increment must be zero or greater");
}
out {
// want to state assert(count == old(count) + increment);
}
do {
this.count += increment;
}
}
```
old(count) is the value of count on entry to incrementBy()
old count is Eiffel syntax.
How is this done in D?
More information about the Digitalmars-d-learn
mailing list