DMD 0.177 release
Andrei Alexandrescu (See Website for Email)
SeeWebsiteForEmail at erdani.org
Mon Dec 11 12:50:19 PST 2006
Bruno Medeiros wrote:
> "allow controlled overwriting of their state" -> Would that be for the
> case where the struct's private state (aka abstract state) is not just
> the bit pattern value of the struct, but also the contents of
> pointer/reference members?
That too. The canonical example is simpler - reject invalid attempts at
setting state. Consider:
struct BoundedInt(int min, int max) {
...
}
alias BoundedInt!(0, 100) Percent;
Percent soFar = 0;
...
soFar = bytesCopied * 100 / bytesToCopy;
Upon assignment, the bounded int structure should do a runtime check to
make sure it is being set to a number within bounds.
Andrei
More information about the Digitalmars-d-announce
mailing list