In C# I could use Contract.OldValue<T>
in a post-condition to check how a field has changed. How can I do this in D? I've read the relevant page in the documentation, but it doesn't mention this.
Specifically, I'm writing a page renderer and am keeping track of how far down the page it's got in a member variable. I'd like to assert in an out
block that the variable's value is at least as large as it was at the start (i.e. it should have moved down the page, not up).
class Renderer
{
private:
float pos;
public:
void writeText(string text)
in
{
assert(text !is null);
}
out
{
// how to do this?
assert(pos >= oldPos);
}
body
{
...
}
}
Obviously I could add another field just to hold the old value, and manually assign it at the start of the writeText
method, but I'm hoping there's something in the framework that will do this automatically.