Re: The relationship of invariants and alias this

2014-11-11 Thread angel via Digitalmars-d
Wait ! x.value -= 100; would call the invariant ? Alias this only rewrites your expression: x -= 100; becomes x.value -= 100; No method is called. Then there is no reason (is there ?) to call the invariant. If you would create getter/setter properties ...

Re: The relationship of invariants and alias this

2014-11-11 Thread Mark Isaacson via Digitalmars-d
On Tuesday, 11 November 2014 at 08:18:36 UTC, angel wrote: Wait ! x.value -= 100; would call the invariant ? Alias this only rewrites your expression: x -= 100; becomes x.value -= 100; No method is called. Then there is no reason (is there ?) to call the invariant. If you would create

Re: The relationship of invariants and alias this

2014-11-11 Thread ZombineDev via Digitalmars-d
AFAIU, even if you had a getter in the alias this: --- import std.stdio; struct ValueRestrictedInteger(int lowerBound, int upperBound) { int value; auto ref get() { return value; } alias get this; this (int rhs) { value = rhs; } invariant() { assert (value = lowerBound

Re: The relationship of invariants and alias this

2014-11-11 Thread Steven Schveighoffer via Digitalmars-d
On 11/11/14 6:48 AM, ZombineDev wrote: AFAIU, even if you had a getter in the alias this: --- import std.stdio; struct ValueRestrictedInteger(int lowerBound, int upperBound) { int value; auto ref get() { return value; } alias get this; this (int rhs) { value = rhs; }

The relationship of invariants and alias this

2014-11-10 Thread Mark Isaacson via Digitalmars-d
I've encountered something which is probably intentional behavior, but that I think is interesting and may merit discussion. When you do alias this and have an invariant, any methods that are forwarded to the aliased member do not invoke your invariant methods. This prevents me from writing

Re: The relationship of invariants and alias this

2014-11-10 Thread Mark Isaacson via Digitalmars-d
Should be noted that this behavior is the same regardless of whether or not I do an alias this on a primitive type as shown above or on a user defined type.

Re: The relationship of invariants and alias this

2014-11-10 Thread H. S. Teoh via Digitalmars-d
On Tue, Nov 11, 2014 at 05:03:00AM +, Mark Isaacson via Digitalmars-d wrote: Should be noted that this behavior is the same regardless of whether or not I do an alias this on a primitive type as shown above or on a user defined type. Sounds like a bug. Please file an issue at

Re: The relationship of invariants and alias this

2014-11-10 Thread Mark Isaacson via Digitalmars-d
On Tuesday, 11 November 2014 at 06:21:18 UTC, H. S. Teoh via Digitalmars-d wrote: On Tue, Nov 11, 2014 at 05:03:00AM +, Mark Isaacson via Digitalmars-d wrote: Should be noted that this behavior is the same regardless of whether or not I do an alias this on a primitive type as shown above