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 ...
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
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
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; }
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
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.
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
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